Class: Harbor::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Harbor::Request
- Defined in:
- lib/harbor/request.rb
Direct Known Subclasses
Constant Summary collapse
- BOT_AGENTS =
[ /yahoo.*slurp/i, /googlebot/i, /msnbot/i, /charlotte.*searchme/i, /twiceler.*robot/i, /dotbot/i, /gigabot/i, /yanga.*bot/i, /gaisbot/i, /becomebot/i, /yandex/i, /catchbot/i, /cazoodlebot/i, /jumblebot/i, /librabot/i, /jyxobot/i, /mlbot/i, /cipinetbot/i, /funnelbot/i, /mj12bot/i, /spinn3r/i, /nutch.*bot/i, /oozbot/i, /robotgenius/i, /snapbot/i, /tmangobot/i, /yacybot/i, /rpt.*httpclient/i, /indy.*library/i, /baiduspider/i, /WhistleBlower/i, /Pingdom/ ].freeze
Instance Attribute Summary collapse
-
#application ⇒ Object
Returns the value of attribute application.
-
#layout ⇒ Object
Returns the value of attribute layout.
Instance Method Summary collapse
- #bot? ⇒ Boolean
- #environment ⇒ Object
- #fetch(key, default_value = nil) ⇒ Object
-
#initialize(application, env) ⇒ Request
constructor
A new instance of Request.
- #message(key) ⇒ Object
- #messages ⇒ Object
- #params ⇒ Object
-
#path ⇒ Object
Returns String:: The URI without the query string.
- #protocol ⇒ Object
- #referer ⇒ Object
- #remote_ip ⇒ Object
- #request_method ⇒ Object
- #session ⇒ Object
- #session? ⇒ Boolean
- #ssl? ⇒ Boolean
- #uri ⇒ Object
Constructor Details
#initialize(application, env) ⇒ Request
Returns a new instance of Request.
45 46 47 48 49 |
# File 'lib/harbor/request.rb', line 45 def initialize(application, env) raise ArgumentError.new("+env+ must be a Rack Environment Hash") unless env.is_a?(Hash) @application = application super(env) end |
Instance Attribute Details
#application ⇒ Object
Returns the value of attribute application.
43 44 45 |
# File 'lib/harbor/request.rb', line 43 def application @application end |
#layout ⇒ Object
Returns the value of attribute layout.
42 43 44 |
# File 'lib/harbor/request.rb', line 42 def layout @layout end |
Instance Method Details
#bot? ⇒ Boolean
59 60 61 62 |
# File 'lib/harbor/request.rb', line 59 def bot? user_agent = env["HTTP_USER_AGENT"] BOT_AGENTS.any? { |bot_agent| user_agent =~ bot_agent } end |
#environment ⇒ Object
81 82 83 |
# File 'lib/harbor/request.rb', line 81 def environment @env['APP_ENVIRONMENT'] || (@application ? @application.environment : "development") end |
#fetch(key, default_value = nil) ⇒ Object
51 52 53 54 55 56 57 |
# File 'lib/harbor/request.rb', line 51 def fetch(key, default_value = nil) if (value = self[key]).nil? || value == '' default_value else value end end |
#message(key) ⇒ Object
119 120 121 |
# File 'lib/harbor/request.rb', line 119 def (key) [key] end |
#messages ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/harbor/request.rb', line 111 def @messages ||= if session? session[:messages] = Messages.new(session[:messages]) else params["messages"] = Messages.new(params["messages"]) end end |
#params ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/harbor/request.rb', line 85 def params params = begin self.GET && self.GET.update(self.POST || {}) rescue EOFError => e self.GET end params || {} end |
#path ⇒ Object
Returns
- String
-
The URI without the query string. Strips trailing “/” and reduces duplicate “/” to a single “/”.
127 128 129 130 131 |
# File 'lib/harbor/request.rb', line 127 def path path = (uri.empty? ? '/' : uri.split('?').first).squeeze("/") path = path[0..-2] if (path[-1] == ?/) && path.size > 1 path end |
#protocol ⇒ Object
95 96 97 |
# File 'lib/harbor/request.rb', line 95 def protocol ssl? ? 'https://' : 'http://' end |
#referer ⇒ Object
103 104 105 |
# File 'lib/harbor/request.rb', line 103 def referer @env['HTTP_REFERER'] end |
#remote_ip ⇒ Object
72 73 74 |
# File 'lib/harbor/request.rb', line 72 def remote_ip env["REMOTE_ADDR"] || env["HTTP_CLIENT_IP"] || env["HTTP_X_FORWARDED_FOR"] end |
#request_method ⇒ Object
76 77 78 79 |
# File 'lib/harbor/request.rb', line 76 def request_method @env['REQUEST_METHOD'] = self.POST['_method'].upcase if request_method_in_params? @env['REQUEST_METHOD'] end |
#session ⇒ Object
64 65 66 |
# File 'lib/harbor/request.rb', line 64 def session @session ||= Harbor::Session.new(self) end |
#session? ⇒ Boolean
68 69 70 |
# File 'lib/harbor/request.rb', line 68 def session? @session end |
#ssl? ⇒ Boolean
99 100 101 |
# File 'lib/harbor/request.rb', line 99 def ssl? @env['HTTPS'] == 'on' || @env['HTTP_X_FORWARDED_PROTO'] == 'https' end |
#uri ⇒ Object
107 108 109 |
# File 'lib/harbor/request.rb', line 107 def uri @env['REQUEST_URI'] || @env['REQUEST_PATH'] end |