Class: Tilia::Http::RequestDecorator
- Inherits:
-
Object
- Object
- Tilia::Http::RequestDecorator
- Includes:
- MessageDecoratorTrait, RequestInterface
- Defined in:
- lib/tilia/http/request_decorator.rb
Overview
Request Decorator
This helper class allows you to easily create decorators for the Request object.
Instance Method Summary collapse
-
#absolute_url ⇒ String
Returns the absolute url.
-
#absolute_url=(url) ⇒ void
Sets the absolute url.
-
#base_url ⇒ String
Returns the current base url.
-
#base_url=(url) ⇒ void
Sets a base url.
-
#initialize(inner) ⇒ RequestDecorator
constructor
Constructor.
-
#method ⇒ String
Returns the current HTTP method.
-
#method=(method) ⇒ void
Sets the HTTP method.
-
#path ⇒ String
Returns the relative path.
-
#post_data ⇒ Object
Returns the POST data.
-
#post_data=(post_data) ⇒ void
Sets the post data.
-
#query_parameters ⇒ Object
Returns the list of query parameters.
-
#raw_server_data=(data) ⇒ void
Sets the _SERVER array.
-
#raw_server_value(value_name) ⇒ String?
Returns an item from the _SERVER array.
-
#to_s ⇒ String
Serializes the request object as a string.
-
#url ⇒ String
Returns the request url.
-
#url=(url) ⇒ void
Sets the request url.
Methods included from MessageDecoratorTrait
#add_header, #add_headers, #body, #body=, #body_as_stream, #body_as_string, #header, #header?, #header_as_array, #headers, #http_version, #http_version=, #remove_header, #update_header, #update_headers
Methods included from MessageInterface
#add_header, #add_headers, #body, #body=, #body_as_stream, #body_as_string, #header, #header?, #header_as_array, #headers, #http_version, #http_version=, #remove_header, #update_header, #update_headers
Constructor Details
#initialize(inner) ⇒ RequestDecorator
Constructor.
14 15 16 |
# File 'lib/tilia/http/request_decorator.rb', line 14 def initialize(inner) @inner = inner end |
Instance Method Details
#absolute_url ⇒ String
Returns the absolute url.
51 52 53 |
# File 'lib/tilia/http/request_decorator.rb', line 51 def absolute_url @inner.absolute_url end |
#absolute_url=(url) ⇒ void
This method returns an undefined value.
Sets the absolute url.
59 60 61 |
# File 'lib/tilia/http/request_decorator.rb', line 59 def absolute_url=(url) @inner.absolute_url = url end |
#base_url ⇒ String
Returns the current base url.
66 67 68 |
# File 'lib/tilia/http/request_decorator.rb', line 66 def base_url @inner.base_url end |
#base_url=(url) ⇒ void
This method returns an undefined value.
Sets a base url.
This url is used for relative path calculations.
The base url should default to /
78 79 80 |
# File 'lib/tilia/http/request_decorator.rb', line 78 def base_url=(url) @inner.base_url = url end |
#method ⇒ String
Returns the current HTTP method
21 22 23 |
# File 'lib/tilia/http/request_decorator.rb', line 21 def method @inner.method end |
#method=(method) ⇒ void
This method returns an undefined value.
Sets the HTTP method
29 30 31 |
# File 'lib/tilia/http/request_decorator.rb', line 29 def method=(method) @inner.method = method end |
#path ⇒ String
Returns the relative path.
This is being calculated using the base url. This path will not start with a slash, so it will always return something like ‘example/path.html’.
If the full path is equal to the base url, this method will return an empty string.
This method will also urldecode the path, and if the url was incoded as ISO-8859-1, it will convert it to UTF-8.
If the path is outside of the base url, a LogicException will be thrown.
97 98 99 |
# File 'lib/tilia/http/request_decorator.rb', line 97 def path @inner.path end |
#post_data ⇒ Object
Returns the POST data.
This is equivalent to PHP’s $_POST superglobal.
115 116 117 |
# File 'lib/tilia/http/request_decorator.rb', line 115 def post_data @inner.post_data end |
#post_data=(post_data) ⇒ void
This method returns an undefined value.
Sets the post data.
This is equivalent to PHP’s $_POST superglobal.
This would not have been needed, if POST data was accessible as php://input, but unfortunately we need to special case it.
128 129 130 |
# File 'lib/tilia/http/request_decorator.rb', line 128 def post_data=(post_data) @inner.post_data = post_data end |
#query_parameters ⇒ Object
Returns the list of query parameters.
This is equivalent to PHP’s $_GET superglobal.
106 107 108 |
# File 'lib/tilia/http/request_decorator.rb', line 106 def query_parameters @inner.query_parameters end |
#raw_server_data=(data) ⇒ void
This method returns an undefined value.
Sets the _SERVER array.
146 147 148 |
# File 'lib/tilia/http/request_decorator.rb', line 146 def raw_server_data=(data) @inner.raw_server_data = data end |
#raw_server_value(value_name) ⇒ String?
Returns an item from the _SERVER array.
If the value does not exist in the array, null is returned.
138 139 140 |
# File 'lib/tilia/http/request_decorator.rb', line 138 def raw_server_value(value_name) @inner.raw_server_value(value_name) end |
#to_s ⇒ String
Serializes the request object as a string.
This is useful for debugging purposes.
155 156 157 |
# File 'lib/tilia/http/request_decorator.rb', line 155 def to_s @inner.to_s end |
#url ⇒ String
Returns the request url.
36 37 38 |
# File 'lib/tilia/http/request_decorator.rb', line 36 def url @inner.url end |
#url=(url) ⇒ void
This method returns an undefined value.
Sets the request url.
44 45 46 |
# File 'lib/tilia/http/request_decorator.rb', line 44 def url=(url) @inner.url = url end |