Class: Wukong::HttpRequest
- Inherits:
-
Object
- Object
- Wukong::HttpRequest
- Includes:
- Gorillib::Model
- Defined in:
- lib/wukong-load/models/http_request.rb
Overview
Represents a generic HTTP request.
Instance Method Summary collapse
-
#best_ip_address ⇒ String
Return the "best" IP address from this request.
-
#cookie ⇒ String
Return the HTTP Cookie of this request.
-
#referer ⇒ String
(also: #referrer)
Return the HTTP Referer of this request.
-
#url ⇒ String
Return the URL of this request.
-
#user_agent ⇒ String
Return the HTTP User-Agent of this request.
Instance Method Details
#best_ip_address ⇒ String
Return the "best" IP address from this request.
Will return the first IP address in the HTTP X-Forwarded-For chain if present, otherwise will return the IP address of the request itself.
52 53 54 55 56 57 |
# File 'lib/wukong-load/models/http_request.rb', line 52 def best_ip_address ip_string = headers['X-Forwarded-For'] return ip_address if ip_string.blank? ips = ip_string.split(/\s*,\s*/) ips.empty? ? ip_address : ips.first # client comes first, then proxies in order end |
#cookie ⇒ String
Return the HTTP Cookie of this request.
41 42 43 |
# File 'lib/wukong-load/models/http_request.rb', line 41 def headers['Cookie'] end |
#referer ⇒ String Also known as: referrer
Return the HTTP Referer of this request.
26 27 28 |
# File 'lib/wukong-load/models/http_request.rb', line 26 def referer headers['Referer'] end |
#url ⇒ String
Return the URL of this request.
19 20 21 |
# File 'lib/wukong-load/models/http_request.rb', line 19 def url File.join(headers['Host'] || '', (path || '')) end |
#user_agent ⇒ String
Return the HTTP User-Agent of this request.
34 35 36 |
# File 'lib/wukong-load/models/http_request.rb', line 34 def user_agent headers['User-Agent'] end |