Module: Typhoeus::Response::Status
- Included in:
- Typhoeus::Response
- Defined in:
- lib/typhoeus/response/status.rb
Overview
This module contains logic about the http status.
Instance Method Summary collapse
-
#http_version ⇒ String
Return the http version.
-
#modified? ⇒ Boolean
Return wether the response is modified.
-
#status_message ⇒ String
Return the status message if present.
-
#success? ⇒ Boolean
Return wether the response is a success.
-
#timed_out? ⇒ Boolean
Return wether the response is timed out.
Instance Method Details
#http_version ⇒ String
Return the http version.
38 39 40 |
# File 'lib/typhoeus/response/status.rb', line 38 def http_version @http_version ||= first_header_line ? first_header_line[/HTTP\/(\S+)/, 1] : nil end |
#modified? ⇒ Boolean
Return wether the response is modified.
58 59 60 |
# File 'lib/typhoeus/response/status.rb', line 58 def modified? (mock || return_code == :ok) && response_code && response_code != 304 end |
#status_message ⇒ String
Return the status message if present.
14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/typhoeus/response/status.rb', line 14 def return @status_message if defined?(@status_message) && @status_message return [:status_message] unless [:status_message].nil? # HTTP servers can choose not to include the explanation to HTTP codes. The RFC # states this (http://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4): # Except when responding to a HEAD request, the server SHOULD include an entity containing # an explanation of the error situation [...] # This means 'HTTP/1.1 404' is as valid as 'HTTP/1.1 404 Not Found' and we have to handle it. # # Regexp doc: http://rubular.com/r/eAr1oVYsVa if first_header_line != nil and first_header_line[/\d{3} (.*)$/, 1] != nil @status_message = first_header_line[/\d{3} (.*)$/, 1].chomp else @status_message = nil end end |
#success? ⇒ Boolean
Return wether the response is a success.
48 49 50 |
# File 'lib/typhoeus/response/status.rb', line 48 def success? (mock || return_code == :ok) && response_code && response_code >= 200 && response_code < 300 end |
#timed_out? ⇒ Boolean
Return wether the response is timed out.
68 69 70 |
# File 'lib/typhoeus/response/status.rb', line 68 def timed_out? [:operation_timedout, :couldnt_connect].include?(return_code) end |