Class: Webbed::Response
- Inherits:
-
Object
- Object
- Webbed::Response
- Includes:
- GenericMessage, Helpers::EntityHeadersHelper, Helpers::RackResponseHelper, Helpers::ResponseHeadersHelper
- Defined in:
- lib/webbed/response.rb
Overview
Representation of an HTTP Response.
This class contains the absolute minimum for accessing the different parts of an HTTP Response. Helper modules provide far more functionality.
Constant Summary collapse
- STATUS_CODE_REGEX =
/^(\d{3}) (.*)$/
Instance Attribute Summary collapse
-
#reason_phrase ⇒ String
The Reason Phrase of the Response.
-
#status_code ⇒ #to_i
The Status Code of the Response.
Attributes included from GenericMessage
#entity_body, #headers, #http_version
Instance Method Summary collapse
-
#initialize(status_code, headers, entity_body, options = {}) ⇒ Response
constructor
Creates a new Response.
-
#status_line ⇒ String
(also: #start_line)
The Status-Line of the Response.
Methods included from Helpers::EntityHeadersHelper
#content_length, #content_length=, #content_location, #content_location=, #content_md5, #content_md5=, #content_type, #content_type=
Methods included from Helpers::ResponseHeadersHelper
#age, #age=, #etag, #etag=, #location, #location=
Methods included from Helpers::RackResponseHelper
Methods included from GenericMessage
Constructor Details
#initialize(status_code, headers, entity_body, options = {}) ⇒ Response
Creates a new Response.
The Status Code may be passed in as a string with a Reason Phrase or just a number. If a number is provided, the default Reason Phrase for that Status Code is used.
The method converts the values passed in to their proper types.
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/webbed/response.rb', line 53 def initialize(status_code, headers, entity_body, = {}) if STATUS_CODE_REGEX =~ status_code.to_s self.status_code = $1 self.reason_phrase = $2 else self.status_code = status_code end self.headers = headers self.entity_body = entity_body self.http_version = .delete(:http_version) || 1.1 end |
Instance Attribute Details
#reason_phrase ⇒ String
The Reason Phrase of the Response.
The method returns the Status Code's default reason phrase if the Reason Phrase has not already been set.
29 30 31 |
# File 'lib/webbed/response.rb', line 29 def reason_phrase defined?(@reason_phrase) ? @reason_phrase : @status_code.default_reason_phrase end |
#status_code ⇒ #to_i
The Status Code of the Response.
The method automatically converts the new value to an instance of StatusCode if it is not already one.
17 18 19 |
# File 'lib/webbed/response.rb', line 17 def status_code @status_code end |
Instance Method Details
#status_line ⇒ String Also known as: start_line
The Status-Line of the Response.
74 75 76 |
# File 'lib/webbed/response.rb', line 74 def status_line "#{http_version} #{status_code} #{reason_phrase}\r\n" end |