From 99c46747afdb1048151a9a69dc5465fe6fab7d64 Mon Sep 17 00:00:00 2001 From: Rony Varghese Date: Thu, 7 Feb 2013 20:04:32 +0530 Subject: [PATCH] Adding COPY http request handling --- lib/httparty.rb | 9 +++++++++ lib/httparty/request.rb | 3 ++- spec/httparty/request_spec.rb | 5 +++++ spec/httparty_spec.rb | 6 ++++++ 4 files changed, 22 insertions(+), 1 deletion(-) diff --git a/lib/httparty.rb b/lib/httparty.rb index 0affb257..ed47b7ff 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -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 diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index 33e280af..4440cdba 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -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] diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index 02b0a8af..f944ab24 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -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"}} diff --git a/spec/httparty_spec.rb b/spec/httparty_spec.rb index 592322ff..f0d54c59 100644 --- a/spec/httparty_spec.rb +++ b/spec/httparty_spec.rb @@ -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)