Module: Otto::RequestHelpers
- Defined in:
- lib/otto.rb
Instance Method Summary collapse
- #absolute_suri(host = current_server_name) ⇒ Object
-
#client_ipaddress ⇒ Object
HTTP_X_FORWARDED_FOR is from the ELB (non-https only) and it can take the form: 74.121.244.2, 10.252.130.147 HTTP_X_REAL_IP is from nginx REMOTE_ADDR is from thin There’s no way to get the client IP address in HTTPS.
- #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
346 347 348 349 |
# File 'lib/otto.rb', line 346 def absolute_suri host=current_server_name prefix = local? ? 'http://' : 'https://' [prefix, host, request_path].join end |
#client_ipaddress ⇒ Object
HTTP_X_FORWARDED_FOR is from the ELB (non-https only) and it can take the form: 74.121.244.2, 10.252.130.147 HTTP_X_REAL_IP is from nginx REMOTE_ADDR is from thin There’s no way to get the client IP address in HTTPS.
314 315 316 317 |
# File 'lib/otto.rb', line 314 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
361 362 363 |
# File 'lib/otto.rb', line 361 def name [name.to_s] end |
#cookie?(name) ⇒ Boolean
365 366 367 |
# File 'lib/otto.rb', line 365 def name !(name).to_s.empty? end |
#current_absolute_uri ⇒ Object
369 370 371 372 |
# File 'lib/otto.rb', line 369 def current_absolute_uri prefix = secure? && !local? ? 'https://' : 'http://' [prefix, http_host, request_path].join end |
#current_server ⇒ Object
323 324 325 |
# File 'lib/otto.rb', line 323 def current_server [current_server_name, env['SERVER_PORT']].join(':') end |
#current_server_name ⇒ Object
327 328 329 |
# File 'lib/otto.rb', line 327 def current_server_name env['SERVER_NAME'] end |
#http_host ⇒ Object
331 332 333 |
# File 'lib/otto.rb', line 331 def http_host env['HTTP_HOST'] end |
#local? ⇒ Boolean
351 352 353 |
# File 'lib/otto.rb', line 351 def local? Otto.env?(:dev, :development) && client_ipaddress == '127.0.0.1' end |
#request_method ⇒ Object
319 320 321 |
# File 'lib/otto.rb', line 319 def request_method env['REQUEST_METHOD'] end |
#request_path ⇒ Object
334 335 336 |
# File 'lib/otto.rb', line 334 def request_path env['REQUEST_PATH'] end |
#request_uri ⇒ Object
338 339 340 |
# File 'lib/otto.rb', line 338 def request_uri env['REQUEST_URI'] end |
#root_path ⇒ Object
342 343 344 |
# File 'lib/otto.rb', line 342 def root_path env['SCRIPT_NAME'] end |
#secure? ⇒ Boolean
355 356 357 358 359 |
# File 'lib/otto.rb', line 355 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
305 306 307 |
# File 'lib/otto.rb', line 305 def user_agent env['HTTP_USER_AGENT'] || '[no-user-agent]' end |