-
Notifications
You must be signed in to change notification settings - Fork 977
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
on_data
callback should be passed in the response's status code
#1426
Comments
Hi @catlee, thank you for raising this and sorry for not getting back to you sooner! First things first, let's see what's the challenge here: the Another issue is that, when the After spending some time thinking about this, I came to the following 3 options to address this:
cc @olleolleolle @grosser your input on this would be appreciated 😄! |
@catlee FYI -- I've just opened a PR to add this functionality. It would be great if you could take a look at #1439 and the |
Faraday 2.5.1 has just been released. After upgrading, you'll be able to do the following: client.get('https://www.example.com') do |req|
req.options.on_data = proc do |chunk, _size, env|
puts "got: #{chunk}" if env.status < 300 # ignores redirects
end
end |
That works perfectly thanks 👍🏻 |
If you request a URL with redirects enabled, I don't think there's a way to distinguish between chunks from the initial request or redirected requests.
outputs
And there is no way within
on_data
to distinguish between chunks from the initial response, and chunks from the redirected response.Passing in the response and/or status code, and/or headers, and/or env to the the callback would help handle this case.
The text was updated successfully, but these errors were encountered: