-
Notifications
You must be signed in to change notification settings - Fork 323
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix AutoInflate with encoding other than Encoding::BINARY. #721
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,15 +17,15 @@ def wrap_response(response) | |
:headers => response.headers, | ||
:proxy_headers => response.proxy_headers, | ||
:connection => response.connection, | ||
:body => stream_for(response.connection), | ||
:body => stream_for(response.connection, :encoding => response.body.encoding), | ||
:request => response.request | ||
} | ||
|
||
Response.new(options) | ||
end | ||
|
||
def stream_for(connection) | ||
Response::Body.new(Response::Inflater.new(connection)) | ||
def stream_for(connection, encoding: Encoding::BINARY) | ||
Response::Body.new(Response::Inflater.new(connection), :encoding => encoding) | ||
Comment on lines
+27
to
+28
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
end | ||
|
||
private | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -456,6 +456,15 @@ def setsockopt(*args) | |
|
||
expect(response.to_s).to eq("") | ||
end | ||
|
||
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) | ||
Comment on lines
+460
to
+464
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm struggling to understand this test. client = HTTP.use(:auto_inflate).headers("Accept-Encoding" => "gzip").encoding(encoding) ^^^ |
||
|
||
expect(response.to_s).to eq("#{body}-gzipped") | ||
end | ||
end | ||
|
||
context "with :normalize_uri" do | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's move logic to
stream_for
:Then move and rename
stream_for
to beprivate
wrap_body
: