Class: Rage::Request
- Inherits:
-
Object
- Object
- Rage::Request
- Defined in:
- lib/rage/request.rb
Instance Method Summary collapse
-
#fresh?(etag:, last_modified:) ⇒ Boolean
Check if the request is fresh.
-
#fullpath ⇒ Object
Returns the full path including the query string.
-
#headers ⇒ Object
Get the request headers.
-
#path ⇒ Object
Returns the path of the request.
-
#request_id ⇒ Object
(also: #uuid)
Returns the unique request ID.
-
#url ⇒ Object
Returns the full URL of the request.
-
#user_agent ⇒ Object
Returns the user agent of the request.
Instance Method Details
#fresh?(etag:, last_modified:) ⇒ Boolean
Check if the request is fresh.
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/rage/request.rb', line 27 def fresh?(etag:, last_modified:) # Always render response when no freshness information # is provided in the request. return false unless if_none_match || if_not_modified_since etag_matches?( requested_etags: if_none_match, response_etag: etag ) && not_modified?( request_not_modified_since: if_not_modified_since, response_last_modified: last_modified ) end |
#fullpath ⇒ Object
Returns the full path including the query string.
66 67 68 69 70 |
# File 'lib/rage/request.rb', line 66 def fullpath path = @env["PATH_INFO"] query_string = @env["QUERY_STRING"] query_string.empty? ? path : "#{path}?#{query_string}" end |
#headers ⇒ Object
Get the request headers.
15 16 17 |
# File 'lib/rage/request.rb', line 15 def headers @headers ||= Headers.new(@env) end |
#path ⇒ Object
Returns the path of the request.
59 60 61 |
# File 'lib/rage/request.rb', line 59 def path @env["PATH_INFO"] end |
#request_id ⇒ Object Also known as: uuid
Returns the unique request ID. By default, this ID is internally generated, and all log entries created during the request are tagged with it. Alternatively, you can use the Rage::RequestId middleware to derive the ID from the X-Request-Id
header.
81 82 83 |
# File 'lib/rage/request.rb', line 81 def request_id @env["rage.request_id"] end |
#url ⇒ Object
Returns the full URL of the request.
43 44 45 46 47 48 49 50 51 52 53 54 |
# File 'lib/rage/request.rb', line 43 def url scheme = @env["rack.url_scheme"] host = @env["SERVER_NAME"] port = @env["SERVER_PORT"] path = @env["PATH_INFO"] query_string = @env["QUERY_STRING"] port_part = (scheme == "http" && port == "80") || (scheme == "https" && port == "443") ? "" : ":#{port}" query_part = query_string.empty? ? "" : "?#{query_string}" "#{scheme}://#{host}#{port_part}#{path}#{query_part}" end |
#user_agent ⇒ Object
Returns the user agent of the request.
75 76 77 |
# File 'lib/rage/request.rb', line 75 def user_agent @env["HTTP_USER_AGENT"] end |