Skip to content

Commit 2951f2c

Browse files
committed
move encoding check to response body
1 parent a99fe2c commit 2951f2c

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

lib/http/content_type.rb

+1-7
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,7 @@ def mime_type(str)
2020
# :nodoc:
2121
def charset(str)
2222
md = str.to_s.match CHARSET_RE
23-
md &&= md[1].to_s.strip.gsub(/^"|"$/, "")
24-
25-
begin
26-
md if Encoding.find(md)
27-
rescue ArgumentError
28-
nil
29-
end
23+
md && md[1].to_s.strip.gsub(/^"|"$/, "")
3024
end
3125
end
3226
end

lib/http/response/body.rb

+9-2
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,18 @@ def to_s
3535

3636
fail StateError, "body is being streamed" unless @streaming.nil?
3737

38+
# see issue 312
39+
begin
40+
encoding = Encoding.find @encoding
41+
rescue ArgumentError
42+
encoding = Encoding::BINARY
43+
end
44+
3845
begin
3946
@streaming = false
40-
@contents = "".force_encoding(@encoding)
47+
@contents = "".force_encoding(encoding)
4148
while (chunk = @client.readpartial)
42-
@contents << chunk.force_encoding(@encoding)
49+
@contents << chunk.force_encoding(encoding)
4350
end
4451
rescue
4552
@contents = nil

0 commit comments

Comments
 (0)