Module: Tilia::Http::MessageInterface
- Included in:
- Message, RequestInterface, ResponseInterface
- Defined in:
- lib/tilia/http/message_interface.rb
Overview
The MessageInterface is the base interface that’s used by both the RequestInterface and ResponseInterface.
Instance Method Summary collapse
-
#add_header(_name, _value) ⇒ void
Adds a HTTP header.
-
#add_headers(_headers) ⇒ void
Adds a new set of HTTP headers.
-
#body ⇒ Object
Returns the message body, as it’s internal representation.
-
#body=(_body) ⇒ void
Updates the body resource with a new stream.
-
#body_as_stream ⇒ Object
Returns the body as a readable stream resource.
-
#body_as_string ⇒ String
Returns the body as a string.
-
#header(_name) ⇒ String?
Returns a specific HTTP header, based on it’s name.
-
#header?(_name) ⇒ Boolean
Will return true or false, depending on if a HTTP header exists.
-
#header_as_array(_name) ⇒ String
Returns a HTTP header as an array.
-
#headers ⇒ Object
Returns all the HTTP headers as an array.
-
#http_version ⇒ String
Returns the HTTP version.
-
#http_version=(_version) ⇒ void
Sets the HTTP version.
-
#remove_header(_name) ⇒ Object
Removes a HTTP header.
-
#update_header(_name, _value) ⇒ void
Updates a HTTP header.
-
#update_headers(_headers) ⇒ void
Sets a new set of HTTP headers.
Instance Method Details
#add_header(_name, _value) ⇒ void
This method returns an undefined value.
Adds a HTTP header.
This method will not overwrite any existing HTTP header, but instead add another value. Individual values can be retrieved with getHeadersAsArray.
116 117 |
# File 'lib/tilia/http/message_interface.rb', line 116 def add_header(_name, _value) end |
#add_headers(_headers) ⇒ void
This method returns an undefined value.
Adds a new set of HTTP headers.
Any existing headers will not be overwritten.
125 126 |
# File 'lib/tilia/http/message_interface.rb', line 125 def add_headers(_headers) end |
#body ⇒ Object
Returns the message body, as it’s internal representation.
This could be either a string or a stream.
29 30 |
# File 'lib/tilia/http/message_interface.rb', line 29 def body end |
#body=(_body) ⇒ void
This method returns an undefined value.
Updates the body resource with a new stream.
36 37 |
# File 'lib/tilia/http/message_interface.rb', line 36 def body=(_body) end |
#body_as_stream ⇒ Object
Returns the body as a readable stream resource.
Note that the stream may not be rewindable, and therefore may only be read once.
12 13 |
# File 'lib/tilia/http/message_interface.rb', line 12 def body_as_stream end |
#body_as_string ⇒ String
Returns the body as a string.
Note that because the underlying data may be based on a stream, this method could only work correctly the first time.
21 22 |
# File 'lib/tilia/http/message_interface.rb', line 21 def body_as_string end |
#header(_name) ⇒ String?
Returns a specific HTTP header, based on it’s name.
The name must be treated as case-insensitive. If the header does not exist, this method must return null.
If a header appeared more than once in a HTTP request, this method will concatenate all the values with a comma.
Note that this not make sense for all headers. Some, such as ‘Set-Cookie` cannot be logically combined with a comma. In those cases you should use header_as_array.
68 69 |
# File 'lib/tilia/http/message_interface.rb', line 68 def header(_name) end |
#header?(_name) ⇒ Boolean
Will return true or false, depending on if a HTTP header exists.
51 52 |
# File 'lib/tilia/http/message_interface.rb', line 51 def header?(_name) end |
#header_as_array(_name) ⇒ String
Returns a HTTP header as an array.
For every time the HTTP header appeared in the request or response, an item will appear in the array.
If the header did not exists, this method will return an empty array.
80 81 |
# File 'lib/tilia/http/message_interface.rb', line 80 def header_as_array(_name) end |
#headers ⇒ Object
Returns all the HTTP headers as an array.
Every header is returned as an array, with one or more values.
44 45 |
# File 'lib/tilia/http/message_interface.rb', line 44 def headers end |
#http_version ⇒ String
Returns the HTTP version.
150 151 |
# File 'lib/tilia/http/message_interface.rb', line 150 def http_version end |
#http_version=(_version) ⇒ void
This method returns an undefined value.
Sets the HTTP version.
Should be 1.0 or 1.1.
144 145 |
# File 'lib/tilia/http/message_interface.rb', line 144 def http_version=(_version) end |
#remove_header(_name) ⇒ Object
Removes a HTTP header.
The specified header name must be treated as case-insenstive. This method should return true if the header was successfully deleted, and false if the header did not exist.
135 136 |
# File 'lib/tilia/http/message_interface.rb', line 135 def remove_header(_name) end |
#update_header(_name, _value) ⇒ void
This method returns an undefined value.
Updates a HTTP header.
The case-sensitity of the name value must be retained as-is.
If the header already existed, it will be overwritten.
92 93 |
# File 'lib/tilia/http/message_interface.rb', line 92 def update_header(_name, _value) end |
#update_headers(_headers) ⇒ void
This method returns an undefined value.
Sets a new set of HTTP headers.
The headers array should contain headernames for keys, and their value should be specified as either a string or an array.
Any header that already existed will be overwritten.
104 105 |
# File 'lib/tilia/http/message_interface.rb', line 104 def update_headers(_headers) end |