1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Adding COPY http request handling

This commit is contained in:
Rony Varghese 2013-02-07 20:04:32 +05:30
parent d5c185969d
commit 99c46747af
4 changed files with 22 additions and 1 deletions

View file

@ -434,6 +434,11 @@ module HTTParty
perform_request Net::HTTP::Move, path, options, &block perform_request Net::HTTP::Move, path, options, &block
end end
# Perform a COPY request to a path
def copy(path, options={}, &block)
perform_request Net::HTTP::Copy, path, options, &block
end
# Perform a HEAD request to a path # Perform a HEAD request to a path
def head(path, options={}, &block) def head(path, options={}, &block)
perform_request Net::HTTP::Head, path, options, &block perform_request Net::HTTP::Head, path, options, &block
@ -508,6 +513,10 @@ module HTTParty
Basement.move(*args, &block) Basement.move(*args, &block)
end end
def self.copy(*args, &block)
Basement.move(*args, &block)
end
def self.head(*args, &block) def self.head(*args, &block)
Basement.head(*args, &block) Basement.head(*args, &block)
end end

View file

@ -8,7 +8,8 @@ module HTTParty
Net::HTTP::Delete, Net::HTTP::Delete,
Net::HTTP::Head, Net::HTTP::Head,
Net::HTTP::Options, Net::HTTP::Options,
Net::HTTP::Move Net::HTTP::Move,
Net::HTTP::Copy
] ]
SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic] SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]

View file

@ -369,6 +369,11 @@ describe HTTParty::Request do
@request.perform.should == {"hash" => {"foo" => "bar"}} @request.perform.should == {"hash" => {"foo" => "bar"}}
end end
it "should be handled by COPY transparently" do
@request.http_method = Net::HTTP::Copy
@request.perform.should == {"hash" => {"foo" => "bar"}}
end
it "should be handled by PATCH transparently" do it "should be handled by PATCH transparently" do
@request.http_method = Net::HTTP::Patch @request.http_method = Net::HTTP::Patch
@request.perform.should == {"hash" => {"foo" => "bar"}} @request.perform.should == {"hash" => {"foo" => "bar"}}

View file

@ -497,6 +497,12 @@ describe HTTParty do
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'} end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
end end
it "should fail with redirected COPY" do
lambda do
@klass.copy('/foo', :no_follow => true)
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
end
it "should fail with redirected PUT" do it "should fail with redirected PUT" do
lambda do lambda do
@klass.put('/foo', :no_follow => true) @klass.put('/foo', :no_follow => true)