Module: N::Request
- Included in:
- Context
- Defined in:
- lib/nitro/request.rb
Overview
Encapsulates a request. This is an abstract request typically extended by sub-classes.
Instance Attribute Summary collapse
-
#cookies ⇒ Object
The request cookies.
-
#headers ⇒ Object
(also: #env, #env_table)
The request headers collection.
-
#in ⇒ Object
The request input stream.
-
#params ⇒ Object
(also: #query)
The parsed query parameters collection.
Instance Method Summary collapse
-
#[](param) ⇒ Object
Lookup a query parameter.
-
#[]=(param, value) ⇒ Object
Set a query parameter.
-
#host ⇒ Object
The server host name.
- #host_url ⇒ Object
-
#method ⇒ Object
The request method.
-
#path ⇒ Object
The path is the uri without the query string.
-
#port ⇒ Object
The server port.
-
#protocol ⇒ Object
The request protocol.
-
#query_string ⇒ Object
The request query string.
-
#referer ⇒ Object
Return the referer.
-
#remote_ip ⇒ Object
HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these before falling back to REMOTE_ADDR.
-
#ssl? ⇒ Boolean
Is this an ssl request?.
-
#uri ⇒ Object
The request uri.
Instance Attribute Details
#cookies ⇒ Object
The request cookies.
32 33 34 |
# File 'lib/nitro/request.rb', line 32 def @cookies end |
#headers ⇒ Object Also known as: env, env_table
The request headers collection. Also called the request environment (env).
19 20 21 |
# File 'lib/nitro/request.rb', line 19 def headers @headers end |
#in ⇒ Object
The request input stream.
14 15 16 |
# File 'lib/nitro/request.rb', line 14 def in @in end |
#params ⇒ Object Also known as: query
The parsed query parameters collection.
27 28 29 |
# File 'lib/nitro/request.rb', line 27 def params @params end |
Instance Method Details
#[](param) ⇒ Object
Lookup a query parameter.
117 118 119 |
# File 'lib/nitro/request.rb', line 117 def [](param) @params[param] end |
#[]=(param, value) ⇒ Object
Set a query parameter.
123 124 125 |
# File 'lib/nitro/request.rb', line 123 def []=(param, value) @params[param] = value end |
#host ⇒ Object
The server host name.
107 108 109 |
# File 'lib/nitro/request.rb', line 107 def host @headers['HTTP_HOST'] end |
#host_url ⇒ Object
111 112 113 |
# File 'lib/nitro/request.rb', line 111 def host_url "http://#{host}" end |
#method ⇒ Object
The request method.
66 67 68 |
# File 'lib/nitro/request.rb', line 66 def method @headers['REQUEST_METHOD'].downcase.intern end |
#path ⇒ Object
The path is the uri without the query string.
54 55 56 |
# File 'lib/nitro/request.rb', line 54 def path uri ? uri.split('?').first : '' end |
#port ⇒ Object
The server port.
101 102 103 |
# File 'lib/nitro/request.rb', line 101 def port @headers['SERVER_PORT'].to_i end |
#protocol ⇒ Object
The request protocol.
36 37 38 |
# File 'lib/nitro/request.rb', line 36 def protocol 443 == port ? 'https://' : 'http://' end |
#query_string ⇒ Object
The request query string.
60 61 62 |
# File 'lib/nitro/request.rb', line 60 def query_string @headers['QUERY_STRING'] end |
#referer ⇒ Object
Return the referer. For the initial page in the clickstream there is no referer, set “/” by default.
73 74 75 |
# File 'lib/nitro/request.rb', line 73 def referer return @headers['REFERER'] || '/' end |
#remote_ip ⇒ Object
HTTP_CLIENT_IP and/or HTTP_X_FORWARDED_FOR are set by proxies so check for these before falling back to REMOTE_ADDR. HTTP_X_FORWARDED_FOR may be a comma-delimited list in the case of multiple chained proxies; the first is the originating IP.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/nitro/request.rb', line 85 def remote_ip return @headers['HTTP_CLIENT_IP'] if @headers.include?('HTTP_CLIENT_IP') if @headers.include?('HTTP_X_FORWARDED_FOR') then remote_ips = @headers['HTTP_X_FORWARDED_FOR'].split(',').reject do |ip| ip =~ /^unknown$|^(10|172\.16|192\.168)\./i end return remote_ips.first.strip unless remote_ips.empty? end return @headers['REMOTE_ADDR'] end |
#ssl? ⇒ Boolean
Is this an ssl request?
42 43 44 |
# File 'lib/nitro/request.rb', line 42 def ssl? 443 == port end |
#uri ⇒ Object
The request uri.
48 49 50 |
# File 'lib/nitro/request.rb', line 48 def uri @headers['REQUEST_URI'] end |