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
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
private

View file

@ -9,7 +9,8 @@ module HTTParty
Net::HTTP::Head,
Net::HTTP::Options,
Net::HTTP::Move,
Net::HTTP::Copy
Net::HTTP::Copy,
Net::HTTP::Mkcol
]
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"}})
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
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform
@ -715,6 +720,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.parsed_response).to eq({"hash" => {"foo" => "bar"}})
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
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform
@ -848,6 +858,11 @@ RSpec.describe HTTParty::Request do
expect(@request.perform.code).to eq(304)
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
logger_double = double
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"}})
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
@redirect['Set-Cookie'] = 'foo=bar; name=value; HTTPOnly'
@request.perform

View file

@ -602,6 +602,12 @@ RSpec.describe HTTParty do
@klass.options('/foo', no_follow: true)
end.to raise_error(HTTParty::RedirectionTooDeep) {|e| expect(e.response.body).to eq('first redirect')}
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
describe "head requests should follow redirects requesting HEAD only" do