Permalink
Browse files

Adding COPY http request handling

  • Loading branch information...
1 parent d5c1859 commit 99c46747afdb1048151a9a69dc5465fe6fab7d64 @ronyv89 ronyv89 committed Feb 7, 2013
Showing with 22 additions and 1 deletion.
  1. +9 −0 lib/httparty.rb
  2. +2 −1 lib/httparty/request.rb
  3. +5 −0 spec/httparty/request_spec.rb
  4. +6 −0 spec/httparty_spec.rb
View
@@ -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
@@ -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
View
@@ -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]
@@ -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"}}
View
@@ -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)

0 comments on commit 99c4674

Please sign in to comment.