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

Adding COPY request handling #190

Merged
merged 1 commit into from
Feb 7, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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