Skip to content

Conversation

@benubois
Copy link
Contributor

@benubois benubois commented Aug 4, 2022

Fix for #535

@tarcieri tarcieri requested a review from ixti August 4, 2022 01:47
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)
Copy link
Member

Choose a reason for hiding this comment

The 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)

^^^ 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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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),
Copy link
Member

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:

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

@ixti ixti self-assigned this Jun 21, 2025
@ixti ixti added this to the v6.0.0 milestone Jun 30, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants