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

maintain blocks passed to 'perform' in redirects #191

Merged
merged 3 commits into from
Apr 10, 2013

Conversation

bmuller
Copy link
Contributor

@bmuller bmuller commented Mar 12, 2013

Blocks passed to requests only get executed on the first HTTP request and don't get executed on future requests caused by a redirect.

For instance:

HTTParty.get("http://google.com") { |chunk| puts "Got a chunk: #{chunk}\n\n" }

will only print out the lines for the 301 response, but will not be run for the following request.

@jnunemaker
Copy link
Owner

A regression test to confirm that this works is all the pull needs. Without one, I'm sure I'll break it down the road.

@bmuller
Copy link
Contributor Author

bmuller commented Mar 26, 2013

Test added. Let me know if you need anything else.

Thanks!

Brian

@bmuller
Copy link
Contributor Author

bmuller commented Mar 27, 2013

This also fixes another issue (fixed in 3f4a2db) where response.body was returning a Net::ReadAdapter. You can see this behavior by running:

response = HTTParty.get("https://www.google.com/") { |chunk| }
response.body

The last line returns an empty Net::ReadAdapter rather than a string. This is due to calling read_body on the response if a block is present - and all subsequent calls to body will be Net::ReadAdapters rather than strings.

jnunemaker pushed a commit that referenced this pull request Apr 10, 2013
maintain blocks passed to 'perform' in redirects
@jnunemaker jnunemaker merged commit b165661 into jnunemaker:master Apr 10, 2013
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.

2 participants