Class: Rage::Request
- Inherits:
-
Object
- Object
- Rage::Request
- Defined in:
- lib/rage/request.rb
Instance Method Summary collapse
-
#delete? ⇒ Boolean
Check the HTTP request method to see if it was of type
DELETE. -
#domain(tld_length = 1) ⇒ Object
Get the domain part of the request.
-
#env ⇒ Hash
Get the Rack environment hash.
-
#format ⇒ String?
Get the content type of the request.
-
#fresh?(etag:, last_modified:) ⇒ Boolean
Check if the request is fresh.
-
#fullpath ⇒ String
Get the request path including the query string.
-
#get? ⇒ Boolean
Check the HTTP request method to see if it was of type
GET. -
#head? ⇒ Boolean
Check the HTTP request method to see if it was of type
HEAD. -
#headers ⇒ Object
Get the request headers.
-
#host ⇒ String
Get the hostname from the request.
-
#method ⇒ String
Get the HTTP method of the request.
-
#patch? ⇒ Boolean
Check the HTTP request method to see if it was of type
PATCH. -
#path ⇒ String
Get the request path.
-
#port ⇒ Integer
Get the port number from the request.
-
#post? ⇒ Boolean
Check the HTTP request method to see if it was of type
POST. -
#protocol ⇒ String
Returns
https://if this was an HTTPS request andhttp://otherwise. -
#put? ⇒ Boolean
Check the HTTP request method to see if it was of type
PUT. -
#query_string ⇒ String
Get the query string from the request.
-
#request_id ⇒ String
(also: #uuid)
Get the unique request ID.
-
#route_uri_pattern ⇒ String
Get the route URI pattern matched for this request.
-
#ssl? ⇒ Boolean
Check if the request was made using TLS/SSL which is if http or https protocol is used inside the URL.
-
#url ⇒ String
Get the full request URL.
-
#user_agent ⇒ String?
Get the
User-Agentheader value.
Instance Method Details
#delete? ⇒ Boolean
Check the HTTP request method to see if it was of type DELETE.
108 109 110 |
# File 'lib/rage/request.rb', line 108 def delete? rack_request.delete? end |
#domain(tld_length = 1) ⇒ Object
Get the domain part of the request.
189 190 191 |
# File 'lib/rage/request.rb', line 189 def domain(tld_length = 1) extract_domain(host, tld_length) end |
#env ⇒ Hash
Get the Rack environment hash.
78 79 80 |
# File 'lib/rage/request.rb', line 78 def env @env end |
#format ⇒ String?
Get the content type of the request.
150 151 152 |
# File 'lib/rage/request.rb', line 150 def format rack_request.content_type end |
#fresh?(etag:, last_modified:) ⇒ Boolean
Check if the request is fresh.
170 171 172 173 174 175 176 177 178 179 180 181 |
# File 'lib/rage/request.rb', line 170 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 ⇒ String
Get the request path including the query string.
136 137 138 |
# File 'lib/rage/request.rb', line 136 def fullpath rack_request.fullpath end |
#get? ⇒ Boolean
Check the HTTP request method to see if it was of type GET.
84 85 86 |
# File 'lib/rage/request.rb', line 84 def get? rack_request.get? end |
#head? ⇒ Boolean
Check the HTTP request method to see if it was of type HEAD.
114 115 116 |
# File 'lib/rage/request.rb', line 114 def head? rack_request.head? end |
#headers ⇒ Object
Get the request headers.
158 159 160 |
# File 'lib/rage/request.rb', line 158 def headers @headers ||= Headers.new(@env) end |
#host ⇒ String
Get the hostname from the request.
60 61 62 |
# File 'lib/rage/request.rb', line 60 def host rack_request.host end |
#method ⇒ String
Get the HTTP method of the request. If the client is using the Rack::MethodOverride middleware, then the X-HTTP-Method-Override header is checked first.
196 197 198 |
# File 'lib/rage/request.rb', line 196 def method check_method(@env["rack.methodoverride.original_method"] || @env["REQUEST_METHOD"]) end |
#patch? ⇒ Boolean
Check the HTTP request method to see if it was of type PATCH.
96 97 98 |
# File 'lib/rage/request.rb', line 96 def patch? rack_request.patch? end |
#path ⇒ String
Get the request path.
128 129 130 |
# File 'lib/rage/request.rb', line 128 def path rack_request.path end |
#port ⇒ Integer
Get the port number from the request.
66 67 68 |
# File 'lib/rage/request.rb', line 66 def port rack_request.port end |
#post? ⇒ Boolean
Check the HTTP request method to see if it was of type POST.
90 91 92 |
# File 'lib/rage/request.rb', line 90 def post? rack_request.post? end |
#protocol ⇒ String
Returns https:// if this was an HTTPS request and http:// otherwise.
54 55 56 |
# File 'lib/rage/request.rb', line 54 def protocol ssl? ? "https://" : "http://" end |
#put? ⇒ Boolean
Check the HTTP request method to see if it was of type PUT.
102 103 104 |
# File 'lib/rage/request.rb', line 102 def put? rack_request.put? end |
#query_string ⇒ String
Get the query string from the request.
72 73 74 |
# File 'lib/rage/request.rb', line 72 def query_string rack_request.query_string end |
#request_id ⇒ String Also known as: uuid
Get 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.
203 204 205 |
# File 'lib/rage/request.rb', line 203 def request_id @env["rage.request_id"] end |
#route_uri_pattern ⇒ String
Get the route URI pattern matched for this request.
215 216 217 218 219 220 221 |
# File 'lib/rage/request.rb', line 215 def route_uri_pattern if @controller Rage::Router::Util.route_uri_pattern(@controller.class, @controller.action_name) else path end end |
#ssl? ⇒ Boolean
Check if the request was made using TLS/SSL which is if http or https protocol is used inside the URL.
48 49 50 |
# File 'lib/rage/request.rb', line 48 def ssl? rack_request.ssl? end |
#url ⇒ String
Get the full request URL.
120 121 122 |
# File 'lib/rage/request.rb', line 120 def url rack_request.url end |
#user_agent ⇒ String?
Get the User-Agent header value.
144 145 146 |
# File 'lib/rage/request.rb', line 144 def user_agent rack_request.user_agent end |