Class: Wukong::HttpRequest

Inherits:
Object
  • Object
show all
Includes:
Gorillib::Model
Defined in:
lib/wukong-load/models/http_request.rb

Overview

Represents a generic HTTP request.

Instance Method Summary collapse

Instance Method Details

#best_ip_addressString

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.

Returns:

  • (String)


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

Return the HTTP Cookie of this request.

Returns:

  • (String)


41
42
43
# File 'lib/wukong-load/models/http_request.rb', line 41

def cookie
  headers['Cookie']
end

#refererString Also known as: referrer

Return the HTTP Referer of this request.

Returns:

  • (String)


26
27
28
# File 'lib/wukong-load/models/http_request.rb', line 26

def referer
  headers['Referer']
end

#urlString

Return the URL of this request.

Returns:

  • (String)


19
20
21
# File 'lib/wukong-load/models/http_request.rb', line 19

def url
  File.join(headers['Host'] || '', (path || ''))
end

#user_agentString

Return the HTTP User-Agent of this request.

Returns:

  • (String)


34
35
36
# File 'lib/wukong-load/models/http_request.rb', line 34

def user_agent
  headers['User-Agent']
end