Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implemented support for MKCOL method #465

Merged
merged 2 commits into from
Mar 23, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/httparty.rb
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,11 @@ def options(path, options = {}, &block)
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
Expand Down
3 changes: 2 additions & 1 deletion lib/httparty/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ class Request #:nodoc:
Net::HTTP::Head,
Net::HTTP::Options,
Net::HTTP::Move,
Net::HTTP::Copy
Net::HTTP::Copy,
Net::HTTP::Mkcol,
]

SupportedURISchemes = ['http', 'https', 'webcal', nil]
Expand Down
20 changes: 20 additions & 0 deletions spec/httparty/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -594,6 +594,11 @@
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
Expand Down Expand Up @@ -715,6 +720,11 @@
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
Expand Down Expand Up @@ -848,6 +858,11 @@
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
Expand Down Expand Up @@ -914,6 +929,11 @@
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
Expand Down
6 changes: 6 additions & 0 deletions spec/httparty_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -602,6 +602,12 @@ def self.parse uri
@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
Expand Down