Fix AutoInflate with encoding other than Encoding::BINARY.#721
Open
benubois wants to merge 3 commits intohttprb:mainfrom
Open
Fix AutoInflate with encoding other than Encoding::BINARY.#721benubois wants to merge 3 commits intohttprb:mainfrom
benubois wants to merge 3 commits intohttprb:mainfrom
Conversation
tarcieri
reviewed
Aug 4, 2022
tarcieri
approved these changes
Aug 4, 2022
ixti
requested changes
Aug 5, 2022
Comment on lines
+460
to
+464
| it "returns decoded body with the correct charset" do | ||
| encoding = Encoding::Shift_JIS | ||
| client = HTTP.use(:auto_inflate).headers("Accept-Encoding" => "gzip").encoding(encoding) | ||
| body = "もしもし!".encode(encoding, Encoding::UTF_8) | ||
| response = client.post("#{dummy.endpoint}/encoded-body", :body => body) |
Member
There was a problem hiding this comment.
I'm struggling to understand this test.
client = HTTP.use(:auto_inflate).headers("Accept-Encoding" => "gzip").encoding(encoding)^^^ encoding(...) enforces encoding of the response.
Comment on lines
+27
to
+28
| def stream_for(connection, encoding: Encoding::BINARY) | ||
| Response::Body.new(Response::Inflater.new(connection), :encoding => encoding) |
Member
There was a problem hiding this comment.
stream_for can and should be private, and encoding: seems like don't need default value.
| :proxy_headers => response.proxy_headers, | ||
| :connection => response.connection, | ||
| :body => stream_for(response.connection), | ||
| :body => stream_for(response.connection, :encoding => response.body.encoding), |
Member
There was a problem hiding this comment.
Let's move logic to stream_for:
Suggested change
| :body => stream_for(response.connection, :encoding => response.body.encoding), | |
| :body => wrap_body(response), |
Then move and rename stream_for to be private wrap_body:
private
def wrap_body(response)
stream = Response::Inflater.new(response.connection)
Response::Body.new(stream, :encoding => response.body.encoding)
end
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fix for #535