Module: Otto::RequestHelpers
- Defined in:
- lib/otto.rb
Instance Method Summary collapse
- #absolute_suri(host = current_server_name) ⇒ Object
- #ajax? ⇒ Boolean
-
#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
377 378 379 380 |
# File 'lib/otto.rb', line 377 def absolute_suri host=current_server_name prefix = local? ? 'http://' : 'https://' [prefix, host, request_path].join end |
#ajax? ⇒ Boolean
393 394 395 |
# File 'lib/otto.rb', line 393 def ajax? env['HTTP_X_REQUESTED_WITH'].to_s.downcase == 'xmlhttprequest' 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.
352 353 354 355 |
# File 'lib/otto.rb', line 352 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
396 397 398 |
# File 'lib/otto.rb', line 396 def name [name.to_s] end |
#cookie?(name) ⇒ Boolean
399 400 401 |
# File 'lib/otto.rb', line 399 def name !(name).to_s.empty? end |
#current_absolute_uri ⇒ Object
402 403 404 405 |
# File 'lib/otto.rb', line 402 def current_absolute_uri prefix = secure? && !local? ? 'https://' : 'http://' [prefix, http_host, request_path].join end |
#current_server ⇒ Object
359 360 361 |
# File 'lib/otto.rb', line 359 def current_server [current_server_name, env['SERVER_PORT']].join(':') end |
#current_server_name ⇒ Object
362 363 364 |
# File 'lib/otto.rb', line 362 def current_server_name env['SERVER_NAME'] end |
#http_host ⇒ Object
365 366 367 |
# File 'lib/otto.rb', line 365 def http_host env['HTTP_HOST'] end |
#local? ⇒ Boolean
381 382 383 384 385 386 |
# File 'lib/otto.rb', line 381 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
356 357 358 |
# File 'lib/otto.rb', line 356 def request_method env['REQUEST_METHOD'] end |
#request_path ⇒ Object
368 369 370 |
# File 'lib/otto.rb', line 368 def request_path env['REQUEST_PATH'] end |
#request_uri ⇒ Object
371 372 373 |
# File 'lib/otto.rb', line 371 def request_uri env['REQUEST_URI'] end |
#root_path ⇒ Object
374 375 376 |
# File 'lib/otto.rb', line 374 def root_path env['SCRIPT_NAME'] end |
#secure? ⇒ Boolean
387 388 389 390 391 |
# File 'lib/otto.rb', line 387 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
344 345 346 |
# File 'lib/otto.rb', line 344 def user_agent env['HTTP_USER_AGENT'] end |