Class: Strelka::HTTPResponse
- Inherits:
-
Mongrel2::HTTPResponse
- Object
- Mongrel2::HTTPResponse
- Strelka::HTTPResponse
- Extended by:
- Loggability
- Includes:
- Constants, DataUtilities
- Defined in:
- lib/strelka/httpresponse.rb
Overview
An HTTP response class.
Defined Under Namespace
Modules: Negotiation, Session
Constant Summary collapse
- CONTENT_TYPE_CHARSET_RE =
Pattern for matching a 'charset' parameter in a media-type string, such as the Content-type header
/;\s*charset=(?<charset>\S+)\s*/i
Instance Attribute Summary collapse
-
#charset ⇒ Object
Overridden charset of the response's entity body, as either an Encoding or a String.
-
#encodings ⇒ Object
An Array of any encodings that have been applied to the response's entity body, in the order they were applied.
-
#languages ⇒ Object
The natural language(s) of the response's entity body.
-
#notes ⇒ Object
readonly
A auto-vivifying nested Hash that plugins can use to pass data amongst themselves.
Instance Method Summary collapse
-
#cookies ⇒ Object
Returns a Strelka::CookieSet that can be used to manipulate the cookies that are sent with the response, creating it if necessary.
-
#initialize ⇒ HTTPResponse
constructor
Add some instance variables to new HTTPResponses.
-
#normalized_headers ⇒ Object
Overridden to add charset, encodings, and languages to outgoing headers if any of them are set.
-
#request=(request) ⇒ Object
Set the request object associated with this response to
request. -
#reset ⇒ Object
Overridden to reset charset, language, and encoding data, too.
Methods included from DataUtilities
autovivify, deep_copy, stringify_keys, symbolify_keys
Constructor Details
#initialize ⇒ HTTPResponse
Add some instance variables to new HTTPResponses.
27 28 29 30 31 32 33 34 35 |
# File 'lib/strelka/httpresponse.rb', line 27 def initialize( * ) # :notnew: @charset = nil @languages = [] @encodings = [] @notes = Hash.new {|h,k| h[k] = {} } = nil super end |
Instance Attribute Details
#charset ⇒ Object
Overridden charset of the response's entity body, as either an Encoding or a String. This will be appended to the Content-type header when the response is sent to the client, replacing any charset setting in the Content-type header already. Defaults to nil, which will cause the encoding of the entity body object to be used instead unless there's already one present in the Content-type. In any case, if the encoding is Encoding::ASCII_8BIT, no charset will be appended to the content-type header.
50 51 52 |
# File 'lib/strelka/httpresponse.rb', line 50 def charset @charset end |
#encodings ⇒ Object
An Array of any encodings that have been applied to the response's entity body, in the order they were applied. These will be set as the response's Content-Encoding header when it is sent to the client. Defaults to the empty Array.
56 57 58 |
# File 'lib/strelka/httpresponse.rb', line 56 def encodings @encodings end |
#languages ⇒ Object
The natural language(s) of the response's entity body. These will be set as the response's Content-Language header when it is sent to the client. Defaults to the empty Array.
61 62 63 |
# File 'lib/strelka/httpresponse.rb', line 61 def languages @languages end |
#notes ⇒ Object (readonly)
A auto-vivifying nested Hash that plugins can use to pass data amongst themselves. The notes hash is shared between the request and response objects if the request is set on the response with #request=.
66 67 68 |
# File 'lib/strelka/httpresponse.rb', line 66 def notes @notes end |
Instance Method Details
#cookies ⇒ Object
Returns a Strelka::CookieSet that can be used to manipulate the cookies that are sent with the response, creating it if necessary.
95 96 97 98 |
# File 'lib/strelka/httpresponse.rb', line 95 def = Strelka::CookieSet.new unless return end |
#normalized_headers ⇒ Object
Overridden to add charset, encodings, and languages to outgoing headers if any of them are set.
71 72 73 74 75 76 77 78 79 80 |
# File 'lib/strelka/httpresponse.rb', line 71 def normalized_headers headers = super self.add_content_type_charset( headers ) headers.content_encoding ||= self.encodings.join(', ') unless self.encodings.empty? headers.content_language ||= self.languages.join(', ') unless self.languages.empty? self.( headers ) return headers end |
#request=(request) ⇒ Object
Set the request object associated with this response to request.
102 103 104 105 |
# File 'lib/strelka/httpresponse.rb', line 102 def request=( request ) super @notes = request.notes end |
#reset ⇒ Object
Overridden to reset charset, language, and encoding data, too.
84 85 86 87 88 89 90 |
# File 'lib/strelka/httpresponse.rb', line 84 def reset super @charset = nil @languages.clear @encodings.clear end |