kronk 1.7.4 → 1.7.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +7 -1
- data/lib/kronk.rb +1 -1
- data/lib/kronk/response.rb +16 -13
- data/test/test_response.rb +1 -1
- metadata +2 -2
data/History.rdoc
CHANGED
data/lib/kronk.rb
CHANGED
data/lib/kronk/response.rb
CHANGED
@@ -61,29 +61,27 @@ class Kronk
|
|
61
61
|
@headers = @_res.to_hash.dup
|
62
62
|
@headers.keys.each{|h| @headers[h] = @headers[h].join(", ")}
|
63
63
|
|
64
|
-
@encoding = "utf-8" unless @
|
65
|
-
c_type =
|
64
|
+
@encoding = "utf-8" unless @headers["content-type"]
|
65
|
+
c_type = @headers["content-type"] =~ ENCODING_MATCHER
|
66
66
|
@encoding = $2 if c_type
|
67
67
|
@encoding ||= "ASCII-8BIT"
|
68
68
|
@encoding = Encoding.find(@encoding) if defined?(Encoding)
|
69
69
|
|
70
70
|
raw_req, raw_resp, bytes = read_raw_from debug_io
|
71
|
-
@raw
|
71
|
+
@raw = try_force_encoding raw_resp
|
72
72
|
|
73
|
-
@request
|
74
|
-
raw_req = try_force_encoding(raw_req) &&
|
75
|
-
Request.parse(raw_req)
|
73
|
+
@request = request || raw_req && Request.parse(try_force_encoding raw_req)
|
76
74
|
|
77
75
|
@time = 0
|
78
76
|
|
79
77
|
@body = try_force_encoding(@_res.body) if @_res.body
|
80
78
|
@body ||= @raw.split("\r\n\r\n",2)[1]
|
81
79
|
|
82
|
-
@bytes = (@
|
80
|
+
@bytes = (@headers["content-length"] || @body.bytes.count).to_i
|
83
81
|
|
84
82
|
@code = @_res.code
|
85
83
|
|
86
|
-
@parser = Kronk.parser_for @
|
84
|
+
@parser = Kronk.parser_for @headers["content-type"]
|
87
85
|
|
88
86
|
@uri = @request.uri if @request && @request.uri
|
89
87
|
@uri = URI.parse io.path if File === io
|
@@ -143,7 +141,7 @@ class Kronk
|
|
143
141
|
# Ruby inspect.
|
144
142
|
|
145
143
|
def inspect
|
146
|
-
"#<#{self.class}:#{
|
144
|
+
"#<#{self.class}:#{@code} #{self['Content-Type']} #{total_bytes}bytes>"
|
147
145
|
end
|
148
146
|
|
149
147
|
|
@@ -429,7 +427,8 @@ class Kronk
|
|
429
427
|
|
430
428
|
rescue Net::HTTPBadResponse
|
431
429
|
ext = "text/html"
|
432
|
-
ext = File.extname(resp_io.path) if
|
430
|
+
ext = File.extname(resp_io.path)[1..-1] if
|
431
|
+
WinFileIO === resp_io || File === resp_io
|
433
432
|
|
434
433
|
resp_io.rewind
|
435
434
|
resp = HeadlessResponse.new resp_io.read, ext
|
@@ -494,7 +493,6 @@ class Kronk
|
|
494
493
|
end
|
495
494
|
|
496
495
|
|
497
|
-
|
498
496
|
##
|
499
497
|
# Mock response object without a header for body-only http responses.
|
500
498
|
|
@@ -510,7 +508,7 @@ class Kronk
|
|
510
508
|
encoding = body.respond_to?(:encoding) ? body.encoding : "UTF-8"
|
511
509
|
|
512
510
|
@header = {
|
513
|
-
'Content-Type' =>
|
511
|
+
'Content-Type' => "text/#{file_ext}; charset=#{encoding}"
|
514
512
|
}
|
515
513
|
end
|
516
514
|
|
@@ -531,7 +529,12 @@ class Kronk
|
|
531
529
|
# Interface method only. Returns empty hash.
|
532
530
|
|
533
531
|
def to_hash
|
534
|
-
@header
|
532
|
+
head_out = @header.dup
|
533
|
+
head_out.keys.each do |key|
|
534
|
+
head_out[key.downcase] = [head_out.delete(key)]
|
535
|
+
end
|
536
|
+
|
537
|
+
head_out
|
535
538
|
end
|
536
539
|
end
|
537
540
|
end
|
data/test/test_response.rb
CHANGED
@@ -66,7 +66,7 @@ class TestResponse < Test::Unit::TestCase
|
|
66
66
|
|
67
67
|
assert_equal "just this one line!", resp.body
|
68
68
|
enc = "".encoding rescue "UTF-8"
|
69
|
-
assert_equal
|
69
|
+
assert_equal "text/html; charset=#{enc}", resp['Content-Type']
|
70
70
|
end
|
71
71
|
|
72
72
|
|
metadata
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
name: kronk
|
3
3
|
version: !ruby/object:Gem::Version
|
4
4
|
prerelease:
|
5
|
-
version: 1.7.
|
5
|
+
version: 1.7.5
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Jeremie Castagna
|
@@ -10,7 +10,7 @@ autorequire:
|
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
12
|
|
13
|
-
date: 2011-10-
|
13
|
+
date: 2011-10-27 00:00:00 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: json
|