Class: FTW::Response
- Inherits:
-
Object
- Object
- FTW::Response
- Includes:
- HTTP::Message, Protocol
- Defined in:
- lib/ftw/response.rb
Overview
An HTTP Response.
See RFC2616 section 6: <tools.ietf.org/html/rfc2616#section-6>
Constant Summary collapse
- STATUS_REASON_MAP =
Translated from the recommendations listed in RFC2616 section 6.1.1 See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
{ 100 => "Continue", 101 => "Switching Protocols", 200 => "OK", 201 => "Created", 202 => "Accepted", 203 => "Non-Authoritative Information", 204 => "No Content", 205 => "Reset Content", 206 => "Partial Content", 300 => "Multiple Choices", 301 => "Moved Permanently", 302 => "Found", 303 => "See Other", 304 => "Not Modified", 305 => "Use Proxy", 307 => "Temporary Redirect", 400 => "Bad Request", 401 => "Unauthorized", 402 => "Payment Required", 403 => "Forbidden", 404 => "Not Found", 405 => "Method Not Allowed", 406 => "Not Acceptable" }
Constants included from CRLF
Constants included from HTTP::Message
Instance Attribute Summary collapse
-
#reason ⇒ Object
readonly
The reason phrase (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>.
-
#status ⇒ Object
The http status code (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>.
Attributes included from HTTP::Message
Instance Method Summary collapse
-
#error? ⇒ Boolean
Is this response an error?.
-
#initialize ⇒ Response
constructor
Create a new Response.
-
#redirect? ⇒ Boolean
Is this response a redirect?.
-
#status_line ⇒ Object
(also: #start_line)
Get the status-line string, like “HTTP/1.0 200 OK”.
-
#upgrade? ⇒ Boolean
Is this Response the result of a successful Upgrade request?.
Methods included from Protocol
#discard_body, #encode_chunked, #read_body, #read_http_body, #read_http_body_chunked, #read_http_body_length, #read_http_message, #write_all, #write_http_body, #write_http_body_chunked, #write_http_body_normal
Methods included from HTTP::Message
#body, #body=, #body?, #content?, #to_s
Constructor Details
#initialize ⇒ Response
Create a new Response.
53 54 55 56 57 |
# File 'lib/ftw/response.rb', line 53 def initialize super @logger = Cabin::Channel.get @reason = "" # Empty reason string by default. It is not required. end |
Instance Attribute Details
#reason ⇒ Object (readonly)
The reason phrase (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
20 21 22 |
# File 'lib/ftw/response.rb', line 20 def reason @reason end |
#status ⇒ Object
The http status code (RFC2616 6.1.1) See RFC2616 section 6.1.1: <tools.ietf.org/html/rfc2616#section-6.1.1>
16 17 18 |
# File 'lib/ftw/response.rb', line 16 def status @status end |
Instance Method Details
#error? ⇒ Boolean
Is this response an error?
66 67 68 69 |
# File 'lib/ftw/response.rb', line 66 def error? # 4xx and 5xx are errors return @status >= 400 && @status < 600 end |
#redirect? ⇒ Boolean
Is this response a redirect?
60 61 62 63 |
# File 'lib/ftw/response.rb', line 60 def redirect? # redirects are 3xx return @status >= 300 && @status < 400 end |
#status_line ⇒ Object Also known as: start_line
Get the status-line string, like “HTTP/1.0 200 OK”
83 84 85 86 87 88 |
# File 'lib/ftw/response.rb', line 83 def status_line # First line is 'Status-Line' from RFC2616 section 6.1 # Status-Line = HTTP-Version SP Status-Code SP Reason-Phrase CRLF # etc... return "HTTP/#{version} #{status} #{reason}" end |
#upgrade? ⇒ Boolean
Is this Response the result of a successful Upgrade request?
94 95 96 97 98 |
# File 'lib/ftw/response.rb', line 94 def upgrade? return false unless status == 101 # "Switching Protocols" return false unless headers["Connection"] == "Upgrade" return true end |