Skip to content
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

When Following Redirects on_headers Only Emits On First Response #231

Open
Kyrluckechuck opened this issue Apr 13, 2023 · 0 comments
Open

Comments

@Kyrluckechuck
Copy link

Kyrluckechuck commented Apr 13, 2023

Hello!

I don't know if we'll see this issue fixed, but after a ton of debugging and headaches, I've finally tracked down what I think is the cause of all of my redirect issues in the typhoeus release 1.4.0 (from version 1.3.1). That also forced us to move from ethon version 0.12.0 to 0.16.0.

After looking at the ethon code diff, I had come to the same conclusion that other users in the typhoeus had, that the changes here had some unintended side effects. Please see typhoeus/typhoeus#705 for more details.

Filing this issue here since this appears to be the package in question that is having undesired behaviour, which was introduced with #221.

Apologies if this is just being mis-used in typhoeus and this package is not at fault, but that repo has not seen any maintenance in a while (and those tickets haven't drawn any attention) so wanted to file this here in the hopes we may either get a proper workaround (aside from just ignoring the on_headers call since now it's not entirely useful), or even better, an update to fix that.

The current workaround I'm using is not ideal because it leads to the download flow being executed just to do basic content-length header checks, but it's manageable. This is my current on_headers method in order to work around this bug and still do the content-length check for most scenarios (when not involving a redirect):

req.on_headers do |response|
  if (response.code != 301 && response.code != 302)
      HttpHelper.assert_status_code!(response.code)
      raise SomePackage::DownloadFailure, 'Invalid Download File Type' if response.headers['Content-Length'].to_i.zero?
  end
end

For extra context though, this is not the case for on_complete, which will only emit after the final destination or max redirects are reached, which is the behaviour we'd expect.

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

No branches or pull requests

1 participant