1
0
Fork 0
mirror of https://github.com/jnunemaker/httparty synced 2023-03-27 23:23:07 -04:00

Implemented support for MKCOL method

MKCOL - part of the HTTP Extensions for Distributed Authoring (also known as WebDAV) - allow creation of a new collection resource at the location specified.

By extending with MKCOL method, will cover basic WebDAV implementation and make httparty more generic and increase the fun.
This commit is contained in:
nj 2016-03-11 08:43:38 +01:00
parent d6919b5ea6
commit 51eaedb1a9
4 changed files with 33 additions and 1 deletions

View file

@ -538,6 +538,11 @@ module HTTParty
perform_request Net::HTTP::Options, path, options, &block perform_request Net::HTTP::Options, path, options, &block
end end
# Perform a MKCOL request to a path
def mkcol(path, options = {}, &block)
perform_request Net::HTTP::Mkcol, path, options, &block
end
attr_reader :default_options attr_reader :default_options
private private

View file

@ -9,7 +9,8 @@ module HTTParty
Net::HTTP::Head, Net::HTTP::Head,
Net::HTTP::Options, Net::HTTP::Options,
Net::HTTP::Move, Net::HTTP::Move,
Net::HTTP::Copy Net::HTTP::Copy,
Net::HTTP::Mkcol
] ]
SupportedURISchemes = ['http', 'https', 'webcal', nil] SupportedURISchemes = ['http', 'https', 'webcal', nil]

View file

@ -594,6 +594,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end end
it "should be handled by MKCOL transparently" do
@request.http_method = Net::HTTP::Mkcol
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end
it "should keep track of cookies between redirects" do it "should keep track of cookies between redirects" do
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform @request.perform
@ -715,6 +720,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end end
it "should be handled by MKCOL transparently" do
@request.http_method = Net::HTTP::Mkcol
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end
it "should keep track of cookies between redirects" do it "should keep track of cookies between redirects" do
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform @request.perform
@ -848,6 +858,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.code).to eq(304) expect(@request.perform.code).to eq(304)
end end
it "should report 304 with a MKCOL request" do
@request.http_method = Net::HTTP::Mkcol
expect(@request.perform.code).to eq(304)
end
it 'should not log the redirection' do it 'should not log the redirection' do
logger_double = double logger_double = double
expect(logger_double).to receive(:info).once expect(logger_double).to receive(:info).once
@ -914,6 +929,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}}) expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end end
it "should be handled by MKCOL transparently" do
@request.http_method = Net::HTTP::Mkcol
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
end
it "should keep track of cookies between redirects" do it "should keep track of cookies between redirects" do
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly' @redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform @request.perform

View file

@ -602,6 +602,12 @@ RSpec.describe HTTParty do
@klass.options('/foo', no_follow: true) @klass.options('/foo', no_follow: true)
end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')} end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
end end
it "should fail with redirected MKCOL" do
expect do
@klass.mkcol('/foo', no_follow: true)
end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
end
end end
describe "head requests should follow redirects requesting HEAD only" do describe "head requests should follow redirects requesting HEAD only" do