mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
added 207 Multi-Status to the list of legit codes
This commit is contained in:
parent
13018f0199
commit
0b4da8c71b
5 changed files with 5 additions and 4 deletions
|
@ -77,7 +77,7 @@ See RestClient::Resource docs for details.
|
||||||
|
|
||||||
== Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
|
== Exceptions (see http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html)
|
||||||
|
|
||||||
* for results code between 200 and 206 a RestClient::Response will be returned
|
* for results code between 200 and 207 a RestClient::Response will be returned
|
||||||
* for results code 301 and 302 the redirection will be followed if the request is a get or a head
|
* for results code 301 and 302 the redirection will be followed if the request is a get or a head
|
||||||
* for result code 303 the redirection will be followed and the request transformed into a get
|
* for result code 303 the redirection will be followed and the request transformed into a get
|
||||||
* for other cases a RestClient::Exception holding the Response will be raised, a specific exception class will be thrown for know error codes
|
* for other cases a RestClient::Exception holding the Response will be raised, a specific exception class will be thrown for know error codes
|
||||||
|
|
|
@ -37,7 +37,7 @@ module RestClient
|
||||||
# Return the default behavior corresponding to the response code:
|
# Return the default behavior corresponding to the response code:
|
||||||
# the response itself for code in 200..206, redirection for 301 and 302 in get and head cases, redirection for 303 and an exception in other cases
|
# the response itself for code in 200..206, redirection for 301 and 302 in get and head cases, redirection for 303 and an exception in other cases
|
||||||
def return! request = nil, &block
|
def return! request = nil, &block
|
||||||
if (200..206).include? code
|
if (200..207).include? code
|
||||||
self
|
self
|
||||||
elsif [301, 302].include? code
|
elsif [301, 302].include? code
|
||||||
unless [:get, :head].include? args[:method]
|
unless [:get, :head].include? args[:method]
|
||||||
|
|
|
@ -9,6 +9,7 @@ module RestClient
|
||||||
204 => 'No Content',
|
204 => 'No Content',
|
||||||
205 => 'Reset Content',
|
205 => 'Reset Content',
|
||||||
206 => 'Partial Content',
|
206 => 'Partial Content',
|
||||||
|
207 => 'Multi-Status',
|
||||||
300 => 'Multiple Choices',
|
300 => 'Multiple Choices',
|
||||||
301 => 'Moved Permanently',
|
301 => 'Moved Permanently',
|
||||||
302 => 'Found',
|
302 => 'Found',
|
||||||
|
|
|
@ -59,7 +59,7 @@ describe RestClient::Request do
|
||||||
end
|
end
|
||||||
|
|
||||||
it "doesn't classify successful requests as failed" do
|
it "doesn't classify successful requests as failed" do
|
||||||
203.upto(206) do |code|
|
203.upto(207) do |code|
|
||||||
res = mock("result")
|
res = mock("result")
|
||||||
res.stub!(:code).and_return(code.to_s)
|
res.stub!(:code).and_return(code.to_s)
|
||||||
res.stub!(:body).and_return("")
|
res.stub!(:body).and_return("")
|
||||||
|
|
|
@ -66,7 +66,7 @@ describe RestClient::Response do
|
||||||
|
|
||||||
it "should throw an exception for other codes" do
|
it "should throw an exception for other codes" do
|
||||||
RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
|
RestClient::Exceptions::EXCEPTIONS_MAP.each_key do |code|
|
||||||
unless (200..206).include? code
|
unless (200..207).include? code
|
||||||
net_http_res = mock('net http response', :code => code.to_i)
|
net_http_res = mock('net http response', :code => code.to_i)
|
||||||
response = RestClient::Response.create('abc', net_http_res, {})
|
response = RestClient::Response.create('abc', net_http_res, {})
|
||||||
lambda { response.return!}.should raise_error
|
lambda { response.return!}.should raise_error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue