Skip to content

Conversation

@roback
Copy link
Member

@roback roback commented Jan 2, 2025

When I added the middleware that checks the response body size in #32, I introduced a bug where the response bodies for all requests in a redirect "chain" gets included in the body returned in the Twingly::HTTP::Response object.

What I did here was to move the middleware after the FollowRedirects middleware, to ensure we run the middleware on each request, instead of handling all response body chunks at once.

The test I added here (along with some other existing tests), would fail with the following error before this fix:

    1) Twingly::HTTP::Client#post when given a host that redirects when following redirects only returns the body of the final request
      Failure/Error: expect(response.fetch(:body)).to eq("finished!")

        expected: "finished!"
              got: "redirect...finished!"

        (compared using ==)
      Shared Example Group: "common HTTP behaviour for" called from ./spec/lib/twingly/http_spec.rb:554
      # ./spec/lib/twingly/http_spec.rb:159:in `block (5 levels) in <top (required)>'

roback added 2 commits January 2, 2025 16:19
When I added the middleware that checks the response body size in #32,
I introduced a bug where the response bodies for all requests in a
redirect "chain" gets included in the body returned in the `Twingly::HTTP::Response`
object.

What I did here was to move the middleware after the FollowRedirects middleware,
to ensure we run the middleware on each request, instead of handling all response
body chunks at once.

The test I added here (along with some other existing tests), would fail with the
following error before this fix:

    1) Twingly::HTTP::Client#post when given a host that redirects when following redirects only returns the body of the final request
      Failure/Error: expect(response.fetch(:body)).to eq("finished!")

        expected: "finished!"
              got: "redirect...finished!"

        (compared using ==)
      Shared Example Group: "common HTTP behaviour for" called from ./spec/lib/twingly/http_spec.rb:554
      # ./spec/lib/twingly/http_spec.rb:159:in `block (5 levels) in <top (required)>'
Before this it was registered as a request middleware. I didn't think
about that when I added it in #32.

This doesn't seem to make any difference, I just thought it makes sense
to change this anyway, as this middleware works with the response.
@roback roback self-assigned this Jan 2, 2025
Copy link
Contributor

@yendi127 yendi127 left a comment

Choose a reason for hiding this comment

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

LGTM! 🎉

@roback roback merged commit c223278 into master Jan 13, 2025
10 checks passed
@roback roback deleted the fix-redirection-and-response-body-bug branch January 13, 2025 07:56
roback added a commit that referenced this pull request Jan 13, 2025
Because of the fix in #33
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