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

HEAD requests are broken since 0.15.0 (undefined method force_encoding for nil:NilClass) #534

Closed
peret opened this issue May 16, 2017 · 3 comments

Comments

@peret
Copy link

peret commented May 16, 2017

In versions >= 0.15.0 when I do something like HTTParty.head("https://www.google.com"), it fails with this Callstack:

NoMethodError: undefined method `force_encoding' for nil:NilClass
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:280:in `encode_with_ruby_encoding'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:316:in `_encode_body'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:322:in `encode_body'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:350:in `handle_response'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:158:in `perform'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:347:in `handle_response'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty/request.rb:158:in `perform'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty.rb:563:in `perform_request'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty.rb:536:in `head'
	from /Users/peter/.rvm/gems/ruby-2.3.3@ptcshell/gems/httparty-0.15.0/lib/httparty.rb:629:in `head'

It works as expected in version 0.14.0. I'm fairly certain that it is caused by one of the changes in this PR: #513
Specifically number 6 in that list. When I understand correctly, the body that gets passed to #encode_with_ruby_encoding should be nil for most HEAD requests. In earlier versions, the NoMethodError was rescued and the unmodified body (i.e. nil) returned. So this is the commit that broke it: c46663d

I'll provide a PR for this very soon.

@peret
Copy link
Author

peret commented May 16, 2017

I'm sorry, I just now realized that there already is a PR for that: #530 (but apparently no corresponding issue). Feel free to merge either.

@jnunemaker
Copy link
Owner

Closed by #530

@jnunemaker
Copy link
Owner

@peret no problem! Thanks for issue, pr and prompt!

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

2 participants