mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
add default option on head requests
This commit is contained in:
parent
777563f5b9
commit
06e4dcdaed
2 changed files with 24 additions and 1 deletions
|
@ -268,7 +268,9 @@ module HTTParty
|
|||
end
|
||||
|
||||
# Declare that you wish to maintain the chosen HTTP method across redirects.
|
||||
# The default behavior is to follow redirects via the GET method.
|
||||
# The default behavior is to follow redirects via the GET method, except
|
||||
# if you are making a HEAD request, in which case the default is to
|
||||
# follow all redirects with HEAD requests.
|
||||
# If you wish to maintain the original method, you can set this option to true.
|
||||
#
|
||||
# @example
|
||||
|
@ -517,6 +519,9 @@ module HTTParty
|
|||
|
||||
# Perform a HEAD request to a path
|
||||
def head(path, options = {}, &block)
|
||||
unless options.has_key?(:maintain_method_across_redirects)
|
||||
options[:maintain_method_across_redirects] = true
|
||||
end
|
||||
perform_request Net::HTTP::Head, path, options, &block
|
||||
end
|
||||
|
||||
|
|
|
@ -588,6 +588,24 @@ RSpec.describe HTTParty do
|
|||
end
|
||||
end
|
||||
|
||||
describe "head requests should follow redirects requesting HEAD only" do
|
||||
before do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Head, 'http://api.foo.com/v1')
|
||||
@redirect = stub_response 'first redirect', 302
|
||||
@redirect['location'] = 'http://foo.com/bar'
|
||||
allow(HTTParty::Request).to receive_messages(new: @request)
|
||||
end
|
||||
|
||||
it "should set maintain_method_across_redirects option if unspecified" do
|
||||
# This is what I'm trying to do:
|
||||
# expect(@klass.head('/foo').body).to be_nil
|
||||
|
||||
# This is what I get instead:
|
||||
# HTTParty::RedirectionTooDeep: HTTP redirects too deep
|
||||
# from /Users/Lehman/Desktop/Code/httparty/lib/httparty/request.rb:344:in `validate'
|
||||
end
|
||||
end
|
||||
|
||||
describe "with multiple class definitions" do
|
||||
before(:each) do
|
||||
@klass.instance_eval do
|
||||
|
|
Loading…
Reference in a new issue