Module: Otto::RequestHelpers
- Defined in:
- lib/otto/helpers/request.rb
Instance Method Summary collapse
- #absolute_suri(host = current_server_name) ⇒ Object
- #ajax? ⇒ Boolean
- #client_ipaddress ⇒ Object
- #cookie(name) ⇒ Object
- #cookie?(name) ⇒ Boolean
- #current_absolute_uri ⇒ Object
- #current_server ⇒ Object
- #current_server_name ⇒ Object
- #http_host ⇒ Object
- #local? ⇒ Boolean
- #request_method ⇒ Object
- #request_path ⇒ Object
- #request_uri ⇒ Object
- #root_path ⇒ Object
- #secure? ⇒ Boolean
- #user_agent ⇒ Object
Instance Method Details
#absolute_suri(host = current_server_name) ⇒ Object
31 32 33 34 |
# File 'lib/otto/helpers/request.rb', line 31 def absolute_suri host=current_server_name prefix = local? ? 'http://' : 'https://' [prefix, host, request_path].join end |
#ajax? ⇒ Boolean
47 48 49 |
# File 'lib/otto/helpers/request.rb', line 47 def ajax? env['HTTP_X_REQUESTED_WITH'].to_s.downcase == 'xmlhttprequest' end |
#client_ipaddress ⇒ Object
6 7 8 9 |
# File 'lib/otto/helpers/request.rb', line 6 def client_ipaddress env['HTTP_X_FORWARDED_FOR'].to_s.split(/,\s*/).first || env['HTTP_X_REAL_IP'] || env['REMOTE_ADDR'] end |
#cookie(name) ⇒ Object
50 51 52 |
# File 'lib/otto/helpers/request.rb', line 50 def name [name.to_s] end |
#cookie?(name) ⇒ Boolean
53 54 55 |
# File 'lib/otto/helpers/request.rb', line 53 def name !(name).to_s.empty? end |
#current_absolute_uri ⇒ Object
56 57 58 59 |
# File 'lib/otto/helpers/request.rb', line 56 def current_absolute_uri prefix = secure? && !local? ? 'https://' : 'http://' [prefix, http_host, request_path].join end |
#current_server ⇒ Object
13 14 15 |
# File 'lib/otto/helpers/request.rb', line 13 def current_server [current_server_name, env['SERVER_PORT']].join(':') end |
#current_server_name ⇒ Object
16 17 18 |
# File 'lib/otto/helpers/request.rb', line 16 def current_server_name env['SERVER_NAME'] end |
#http_host ⇒ Object
19 20 21 |
# File 'lib/otto/helpers/request.rb', line 19 def http_host env['HTTP_HOST'] end |
#local? ⇒ Boolean
35 36 37 38 39 40 |
# File 'lib/otto/helpers/request.rb', line 35 def local? Otto.env?(:dev, :development) && (client_ipaddress == '127.0.0.1' || !client_ipaddress.match(/^10\.0\./).nil? || !client_ipaddress.match(/^192\.168\./).nil?) end |
#request_method ⇒ Object
10 11 12 |
# File 'lib/otto/helpers/request.rb', line 10 def request_method env['REQUEST_METHOD'] end |
#request_path ⇒ Object
22 23 24 |
# File 'lib/otto/helpers/request.rb', line 22 def request_path env['REQUEST_PATH'] end |
#request_uri ⇒ Object
25 26 27 |
# File 'lib/otto/helpers/request.rb', line 25 def request_uri env['REQUEST_URI'] end |
#root_path ⇒ Object
28 29 30 |
# File 'lib/otto/helpers/request.rb', line 28 def root_path env['SCRIPT_NAME'] end |
#secure? ⇒ Boolean
41 42 43 44 45 |
# File 'lib/otto/helpers/request.rb', line 41 def secure? # X-Scheme is set by nginx # X-FORWARDED-PROTO is set by elastic load balancer (env['HTTP_X_FORWARDED_PROTO'] == 'https' || env['HTTP_X_SCHEME'] == "https") end |
#user_agent ⇒ Object
3 4 5 |
# File 'lib/otto/helpers/request.rb', line 3 def user_agent env['HTTP_USER_AGENT'] end |