Skip to content

Commit

Permalink
Adding COPY http request handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ronyv89 committed Feb 7, 2013
1 parent d5c1859 commit 99c4674
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -434,6 +434,11 @@ def move(path, options={}, &block)
perform_request Net::HTTP::Move, path, options, &block
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
def head(path, options={}, &block)
perform_request Net::HTTP::Head, path, options, &block
Expand Down Expand Up @@ -508,6 +513,10 @@ def self.move(*args, &block)
Basement.move(*args, &block)
end

def self.copy(*args, &block)
Basement.move(*args, &block)
end

def self.head(*args, &block)
Basement.head(*args, &block)
end
Expand Down
3 changes: 2 additions & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ class Request #:nodoc:
Net::HTTP::Delete,
Net::HTTP::Head,
Net::HTTP::Options,
Net::HTTP::Move
Net::HTTP::Move,
Net::HTTP::Copy
]

SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]
Expand Down
5 changes: 5 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,11 @@
@request.perform.should == {"hash" => {"foo" => "bar"}}
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
@request.http_method = Net::HTTP::Patch
@request.perform.should == {"hash" => {"foo" => "bar"}}
Expand Down
6 changes: 6 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -497,6 +497,12 @@ class MyParser < HTTParty::Parser
end.should raise_error(HTTParty::RedirectionTooDeep) {|e| e.response.body.should == 'first redirect'}
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
lambda do
@klass.put('/foo', :no_follow => true)
Expand Down

0 comments on commit 99c4674

Please sign in to comment.