From 0eab9103cd86c4eba7eae4ce6a98479abd62444c Mon Sep 17 00:00:00 2001 From: Fabian Oudhaarlem Date: Wed, 2 May 2018 22:26:33 +0200 Subject: [PATCH 1/2] added lock and unlock http support --- .gitignore | 1 + lib/httparty.rb | 8 ++++++++ lib/httparty/request.rb | 2 ++ lib/httparty/version.rb | 2 +- 4 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 702a7607..ab60ef9d 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,4 @@ pkg/ .rvmrc coverage *.gem +.idea \ No newline at end of file diff --git a/lib/httparty.rb b/lib/httparty.rb index e64dc983..e551ab57 100644 --- a/lib/httparty.rb +++ b/lib/httparty.rb @@ -546,6 +546,14 @@ def mkcol(path, options = {}, &block) perform_request Net::HTTP::Mkcol, path, options, &block end + def lock(path, options = {}, &block) + perform_request Net::HTTP::Lock, path, options, &block + end + + def unlock(path, options = {}, &block) + perform_request Net::HTTP::Unlock, path, options, &block + end + attr_reader :default_options private diff --git a/lib/httparty/request.rb b/lib/httparty/request.rb index e420f86c..17b19913 100644 --- a/lib/httparty/request.rb +++ b/lib/httparty/request.rb @@ -14,6 +14,8 @@ class Request #:nodoc: Net::HTTP::Move, Net::HTTP::Copy, Net::HTTP::Mkcol, + Net::HTTP::Lock, + Net::HTTP::Unlock, ] SupportedURISchemes = ['http', 'https', 'webcal', nil] diff --git a/lib/httparty/version.rb b/lib/httparty/version.rb index d7ac967b..5ffc4dcb 100644 --- a/lib/httparty/version.rb +++ b/lib/httparty/version.rb @@ -1,3 +1,3 @@ module HTTParty - VERSION = "0.16.2" + VERSION = "0.16.3" end From 4df701977cdfb153f2860ce181baccba2af75764 Mon Sep 17 00:00:00 2001 From: Fabian Oudhaarlem Date: Fri, 29 Jun 2018 17:33:21 +0200 Subject: [PATCH 2/2] added tests for lock and unlock --- spec/httparty/request_spec.rb | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/spec/httparty/request_spec.rb b/spec/httparty/request_spec.rb index ec9205c0..24dbf456 100644 --- a/spec/httparty/request_spec.rb +++ b/spec/httparty/request_spec.rb @@ -788,6 +788,16 @@ expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) end + it "should be handled by LOCK transparently" do + @request.http_method = Net::HTTP::Lock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + + it "should be handled by UNLOCK transparently" do + @request.http_method = Net::HTTP::Unlock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + it "should keep track of cookies between redirects" do @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @request.perform @@ -914,6 +924,16 @@ expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) end + it "should be handled by LOCK transparently" do + @request.http_method = Net::HTTP::Lock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + + it "should be handled by UNLOCK transparently" do + @request.http_method = Net::HTTP::Unlock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + it "should keep track of cookies between redirects" do @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @request.perform @@ -1052,6 +1072,16 @@ expect(@request.perform.code).to eq(304) end + it "should be handled by LOCK transparently" do + @request.http_method = Net::HTTP::Lock + expect(@request.perform.code).to eq(304) + end + + it "should be handled by UNLOCK transparently" do + @request.http_method = Net::HTTP::Unlock + expect(@request.perform.code).to eq(304) + end + it 'should not log the redirection' do logger_double = double expect(logger_double).to receive(:info).once @@ -1123,6 +1153,18 @@ expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) end + it "should be handled by LOCK transparently" do + @request.http_method = Net::HTTP::Lock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + + it "should be handled by UNLOCK transparently" do + @request.http_method = Net::HTTP::Unlock + expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) + end + + + it "should keep track of cookies between redirects" do @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @request.perform