Class: Tilia::Http::RequestDecorator

Inherits:
Object
  • Object
show all
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

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.

Parameters:

  • RequestInterface

    inner



14
15
16
# File 'lib/tilia/http/request_decorator.rb', line 14

def initialize(inner)
  @inner = inner
end

Instance Method Details

#absolute_urlString

Returns the absolute url.

Returns:

  • (String)


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.

Parameters:

  • url (String)


59
60
61
# File 'lib/tilia/http/request_decorator.rb', line 59

def absolute_url=(url)
  @inner.absolute_url = url
end

#base_urlString

Returns the current base url.

Returns:

  • (String)


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 /

Parameters:

  • url (String)


78
79
80
# File 'lib/tilia/http/request_decorator.rb', line 78

def base_url=(url)
  @inner.base_url = url
end

#methodString

Returns the current HTTP method

Returns:

  • (String)


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

Parameters:

  • method (String)


29
30
31
# File 'lib/tilia/http/request_decorator.rb', line 29

def method=(method)
  @inner.method = method
end

#pathString

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.

Returns:

  • (String)


97
98
99
# File 'lib/tilia/http/request_decorator.rb', line 97

def path
  @inner.path
end

#post_dataObject

Returns the POST data.

This is equivalent to PHP’s $_POST superglobal.

Returns:

  • array



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.

Parameters:

  • array

    post_data



128
129
130
# File 'lib/tilia/http/request_decorator.rb', line 128

def post_data=(post_data)
  @inner.post_data = post_data
end

#query_parametersObject

Returns the list of query parameters.

This is equivalent to PHP’s $_GET superglobal.

Returns:

  • array



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.

Parameters:

  • array

    data



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.

Parameters:

  • value_name (String)

Returns:

  • (String, nil)


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_sString

Serializes the request object as a string.

This is useful for debugging purposes.

Returns:

  • (String)


155
156
157
# File 'lib/tilia/http/request_decorator.rb', line 155

def to_s
  @inner.to_s
end

#urlString

Returns the request url.

Returns:

  • (String)


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.

Parameters:

  • url (String)


44
45
46
# File 'lib/tilia/http/request_decorator.rb', line 44

def url=(url)
  @inner.url = url
end