Skip to content

Commit

Permalink
Don't guess encoding for text/ mimetype
Browse files Browse the repository at this point in the history
  • Loading branch information
Connorhd authored and ixti committed Dec 13, 2015
1 parent f40fbda commit 8c7c66a
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 12 deletions.
7 changes: 1 addition & 6 deletions lib/http/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,7 @@ def inspect

# Work out what encoding to assume for the body
def resolved_encoding
return @encoding if @encoding
return charset if charset
return Encoding::UTF_8 if mime_type && mime_type.start_with?("text/".freeze)

Encoding::BINARY
@encoding || charset || Encoding::BINARY
end

end
end
12 changes: 6 additions & 6 deletions spec/lib/http_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@
context "loading binary data" do
it "is encoded as bytes" do
response = HTTP.get "#{dummy.endpoint}/bytes"
expect(response.to_s.encoding).to eq(Encoding::ASCII_8BIT)
expect(response.to_s.encoding).to eq(Encoding::BINARY)
end
end

Expand All @@ -175,8 +175,8 @@

context "with encoding option" do
it "respects option" do
response = HTTP.get "#{dummy.endpoint}/iso-8859-1", "encoding" => Encoding::ASCII_8BIT
expect(response.to_s.encoding).to eq(Encoding::ASCII_8BIT)
response = HTTP.get "#{dummy.endpoint}/iso-8859-1", "encoding" => Encoding::BINARY
expect(response.to_s.encoding).to eq(Encoding::BINARY)
end
end
end
Expand All @@ -188,10 +188,10 @@
end
end

context "loading text" do
it "is utf-8 encoded" do
context "loading text with no charset" do
it "is binary encoded" do
response = HTTP.get dummy.endpoint
expect(response.to_s.encoding).to eq(Encoding::UTF_8)
expect(response.to_s.encoding).to eq(Encoding::BINARY)
end
end

Expand Down

0 comments on commit 8c7c66a

Please sign in to comment.