mirror of
https://github.com/jnunemaker/httparty
synced 2023-03-27 23:23:07 -04:00
Added option to maintain HTTP method across redirects.
This commit is contained in:
parent
14fce706a6
commit
0503690df9
4 changed files with 35 additions and 1 deletions
|
@ -166,6 +166,21 @@ module HTTParty
|
|||
default_options[:no_follow] = value
|
||||
end
|
||||
|
||||
# Declare that you wish to maintain the chosen HTTP method across redirects.
|
||||
# The default behavior is to follow redirects via the GET method.
|
||||
# If you wish to maintain the original method, you can set this option to true.
|
||||
#
|
||||
# @example
|
||||
# class Foo
|
||||
# include HTTParty
|
||||
# base_uri 'http://google.com'
|
||||
# maintain_method_across_redirects true
|
||||
# end
|
||||
|
||||
def maintain_method_across_redirects(value = true)
|
||||
default_options[:maintain_method_across_redirects] = value
|
||||
end
|
||||
|
||||
# Allows setting a PEM file to be used
|
||||
#
|
||||
# class Foo
|
||||
|
|
|
@ -157,7 +157,7 @@ module HTTParty
|
|||
options[:limit] -= 1
|
||||
self.path = last_response['location']
|
||||
self.redirect = true
|
||||
self.http_method = Net::HTTP::Get
|
||||
self.http_method = Net::HTTP::Get unless options[:maintain_method_across_redirects]
|
||||
capture_cookies(last_response)
|
||||
perform
|
||||
else
|
||||
|
|
|
@ -364,6 +364,13 @@ describe HTTParty::Request do
|
|||
@request.perform.should == {"hash" => {"foo" => "bar"}}
|
||||
@request.http_method.should == Net::HTTP::Get
|
||||
end
|
||||
|
||||
it 'should not make resulting request a get request if options[:maintain_method_across_redirects] is true' do
|
||||
@request.options[:maintain_method_across_redirects] = true
|
||||
@request.http_method = Net::HTTP::Delete
|
||||
@request.perform.should == {"hash" => {"foo" => "bar"}}
|
||||
@request.http_method.should == Net::HTTP::Delete
|
||||
end
|
||||
end
|
||||
|
||||
describe "infinitely" do
|
||||
|
|
|
@ -323,6 +323,18 @@ describe HTTParty do
|
|||
end
|
||||
end
|
||||
|
||||
describe "#maintain_method_across_redirects" do
|
||||
it "sets maintain_method_across_redirects to true by default" do
|
||||
@klass.maintain_method_across_redirects
|
||||
@klass.default_options[:maintain_method_across_redirects].should be_true
|
||||
end
|
||||
|
||||
it "sets the maintain_method_across_redirects option to false" do
|
||||
@klass.maintain_method_across_redirects false
|
||||
@klass.default_options[:maintain_method_across_redirects].should be_false
|
||||
end
|
||||
end
|
||||
|
||||
describe "with explicit override of automatic redirect handling" do
|
||||
before do
|
||||
@request = HTTParty::Request.new(Net::HTTP::Get, 'http://api.foo.com/v1', :format => :xml, :no_follow => true)
|
||||
|
|
Loading…
Add table
Reference in a new issue