diff --git a/lib/restclient/exceptions.rb b/lib/restclient/exceptions.rb index 8d46f7d..82b8028 100644 --- a/lib/restclient/exceptions.rb +++ b/lib/restclient/exceptions.rb @@ -21,7 +21,7 @@ module RestClient 305 => 'Use Proxy', # http/1.1 306 => 'Switch Proxy', # no longer used 307 => 'Temporary Redirect', # http/1.1 - + 400 => 'Bad Request', 401 => 'Unauthorized', 402 => 'Payment Required', @@ -46,7 +46,7 @@ module RestClient 423 => 'Locked', #WebDAV 424 => 'Failed Dependency', #WebDAV 425 => 'Unordered Collection', #WebDAV - 426 => 'Upgrade Required', + 426 => 'Upgrade Required', 449 => 'Retry With', #Microsoft 450 => 'Blocked By Windows Parental Controls', #Microsoft @@ -112,7 +112,7 @@ module RestClient def to_s inspect end - + def message @message || self.class.name end @@ -166,9 +166,9 @@ module RestClient end end - class MaxRedirectsReached < Exception + class MaxRedirectsReached < Exception def message - 'Maximum number of redirect reached' + 'Maximum number of redirect reached' end end diff --git a/lib/restclient/net_http_ext.rb b/lib/restclient/net_http_ext.rb index ee40e9e..d34f1e4 100644 --- a/lib/restclient/net_http_ext.rb +++ b/lib/restclient/net_http_ext.rb @@ -1,6 +1,6 @@ module Net - class HTTP - + class HTTP + # Adding the patch method if it doesn't exist (rest-client issue: https://github.com/archiloque/rest-client/issues/79) if !defined?(Net::HTTP::Patch) # Code taken from this commit: https://github.com/ruby/ruby/commit/ab70e53ac3b5102d4ecbe8f38d4f76afad29d37d#lib/net/http.rb @@ -10,7 +10,7 @@ module Net def patch(path, data, initheader = nil, dest = nil, &block) # :yield: +body_segment+ send_entity(path, data, initheader, dest, Patch, &block) end - + # Executes a request which uses a representation # and returns its body. def send_entity(path, data, initheader, dest, type, &block) @@ -26,7 +26,7 @@ module Net res end end - + class Patch < HTTPRequest METHOD = 'PATCH' REQUEST_HAS_BODY = true @@ -38,7 +38,7 @@ module Net # Replace the request method in Net::HTTP to sniff the body type # and set the stream if appropriate # - # Taken from: + # Taken from: # http://www.missiondata.com/blog/ruby/29/streaming-data-to-s3-with-ruby/ alias __request__ request diff --git a/spec/abstract_response_spec.rb b/spec/abstract_response_spec.rb index 599ddcd..d593d65 100644 --- a/spec/abstract_response_spec.rb +++ b/spec/abstract_response_spec.rb @@ -64,7 +64,7 @@ describe RestClient::AbstractResponse do it "can access the net http result directly" do @response.net_http_res.should eq @net_http_res end - + describe "#return!" do it "should return the response itself on 200-codes" do @net_http_res.should_receive(:code).and_return('200') @@ -75,7 +75,7 @@ describe RestClient::AbstractResponse do @net_http_res.should_receive(:code).and_return('1000') lambda { @response.return! }.should raise_error RestClient::RequestFailed end - + it "should raise an error on a redirection after non-GET/HEAD requests" do @net_http_res.should_receive(:code).and_return('301') @response.args.merge(:method => :put) diff --git a/spec/exceptions_spec.rb b/spec/exceptions_spec.rb index 6526d94..fbc6fb1 100644 --- a/spec/exceptions_spec.rb +++ b/spec/exceptions_spec.rb @@ -8,14 +8,14 @@ describe RestClient::Exception do e = RestClient::Exception.new e.message.should eq "RestClient::Exception" end - + it "returns the 'message' that was set" do e = RestClient::Exception.new message = "An explicitly set message" e.message = message e.message.should eq message end - + it "sets the exception message to ErrorMessage" do RestClient::ResourceNotFound.new.message.should eq 'Resource Not Found' end diff --git a/spec/payload_spec.rb b/spec/payload_spec.rb index 8cccc46..4e08059 100644 --- a/spec/payload_spec.rb +++ b/spec/payload_spec.rb @@ -55,7 +55,7 @@ describe RestClient::Payload do RestClient::Payload::UrlEncoded.new({:foo => ['bar', 'baz']}).to_s. should eq "foo[]=bar&foo[]=baz" end - + it 'should not close if stream already closed' do p = RestClient::Payload::UrlEncoded.new({'foo ' => 'bar'}) 3.times {p.close} @@ -69,7 +69,7 @@ describe RestClient::Payload do m.stub(:boundary).and_return(123) m.headers['Content-Type'].should eq 'multipart/form-data; boundary=123' end - + it 'should not error on close if stream already closed' do m = RestClient::Payload::Multipart.new(:file => File.new(File.join(File.dirname(File.expand_path(__FILE__)), 'master_shake.jpg'))) 3.times {m.close} diff --git a/spec/response_spec.rb b/spec/response_spec.rb index 4f1d2c4..e794a7c 100644 --- a/spec/response_spec.rb +++ b/spec/response_spec.rb @@ -77,7 +77,7 @@ describe RestClient::Response do end describe "redirection" do - + it "follows a redirection when the request is a get" do stub_request(:get, 'http://some/resource').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://new/resource'}) stub_request(:get, 'http://new/resource').to_return(:body => 'Foo') @@ -149,14 +149,14 @@ describe RestClient::Response do stub_request(:get, 'http://new/resource').to_return(:body => 'Foo') RestClient::Request.execute(:url => 'http://some/resource', :method => :get).body.should eq 'Foo' end - + it "follows no more than 10 redirections before raising error" do stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'}) stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'}) lambda { RestClient::Request.execute(:url => 'http://some/redirect-1', :method => :get) }.should raise_error(RestClient::MaxRedirectsReached) WebMock.should have_requested(:get, 'http://some/redirect-2').times(10) end - + it "follows no more than max_redirects redirections, if specified" do stub_request(:get, 'http://some/redirect-1').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'}) stub_request(:get, 'http://some/redirect-2').to_return(:body => '', :status => 301, :headers => {'Location' => 'http://some/redirect-2'})