Skip to content

Commit

Permalink
* handle a response which has 2XX status code as a successfull respo…
Browse files Browse the repository at this point in the history
…nse while retry check. applied the patch from Micah Wedemeyer. Thanks! closes nahi#158.
  • Loading branch information
nahi committed Jun 30, 2007
1 parent 912ceee commit b4bb057
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/http-access2.rb
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,7 @@ def follow_redirect(uri, query = nil)
retry_number = 0
while retry_number < 10
res = yield(uri, query)
if res.status == HTTP::Status::OK
if HTTP::Status.successful?(res.status)
return res
elsif HTTP::Status.redirect?(res.status)
uri = @redirect_uri_callback.call(uri, res)
Expand Down
19 changes: 19 additions & 0 deletions lib/http-access2/http.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,12 @@ module HTTP

module Status
OK = 200
CREATED = 201
ACCEPTED = 202
NON_AUTHORITATIVE_INFORMATION = 203
NO_CONTENT = 204
RESET_CONTENT = 205
PARTIAL_CONTENT = 206
MOVED_PERMANENTLY = 301
FOUND = 302
SEE_OTHER = 303
Expand All @@ -21,6 +27,14 @@ module Status
PROXY_AUTHENTICATE_REQUIRED = 407
INTERNAL = 500

def self.successful?(status)
[
OK, CREATED, ACCEPTED,
NON_AUTHORITATIVE_INFORMATION, NO_CONTENT,
RESET_CONTENT, PARTIAL_CONTENT
].include?(status)
end

def self.redirect?(status)
[
MOVED_PERMANENTLY, FOUND, SEE_OTHER,
Expand Down Expand Up @@ -89,6 +103,11 @@ class Headers

StatusCodeMap = {
Status::OK => 'OK',
Status::CREATED => "Created",
Status::NON_AUTHORITATIVE_INFORMATION => "Non-Authoritative Information",
Status::NO_CONTENT => "No Content",
Status::RESET_CONTENT => "Reset Content",
Status::PARTIAL_CONTENT => "Partial Content",
Status::MOVED_PERMANENTLY => 'Moved Permanently',
Status::FOUND => 'Found',
Status::SEE_OTHER => 'See Other',
Expand Down

0 comments on commit b4bb057

Please sign in to comment.