Class: Carnivore::Http::App::Request
- Inherits:
-
Rack::Request
- Object
- Rack::Request
- Carnivore::Http::App::Request
- Defined in:
- lib/carnivore-http/app.rb
Overview
Customized request
Instance Attribute Summary collapse
- #locker ⇒ Mutex readonly
- #responder ⇒ ConditionVariable readonly
- #response_value ⇒ Response readonly
Instance Method Summary collapse
- #headers ⇒ Smash
-
#initialize(*_) ⇒ Request
constructor
Override to setup synchronization support.
- #method ⇒ Symbol
- #remote_addr ⇒ String
-
#respond(code, string_or_args = '') ⇒ TrueClass, FalseClass
Respond to the request.
-
#response(timeout = 5) ⇒ Response
Response to this request.
Constructor Details
#initialize(*_) ⇒ Request
Override to setup synchronization support
128 129 130 131 132 |
# File 'lib/carnivore-http/app.rb', line 128 def initialize(*_) super @locker = Mutex.new @responder = ConditionVariable.new end |
Instance Attribute Details
#locker ⇒ Mutex (readonly)
123 124 125 |
# File 'lib/carnivore-http/app.rb', line 123 def locker @locker end |
#responder ⇒ ConditionVariable (readonly)
125 126 127 |
# File 'lib/carnivore-http/app.rb', line 125 def responder @responder end |
#response_value ⇒ Response (readonly)
121 122 123 |
# File 'lib/carnivore-http/app.rb', line 121 def response_value @response_value end |
Instance Method Details
#headers ⇒ Smash
166 167 168 169 170 171 172 |
# File 'lib/carnivore-http/app.rb', line 166 def headers Smash[ env.map do |k,v| k.start_with?('rack.') ? nil : [k.downcase.sub(/^http_/, '').to_sym,v] end.compact ] end |
#method ⇒ Symbol
180 181 182 |
# File 'lib/carnivore-http/app.rb', line 180 def method request_method.to_s.downcase.to_sym end |
#remote_addr ⇒ String
175 176 177 |
# File 'lib/carnivore-http/app.rb', line 175 def remote_addr headers['REMOTE_ADDR'] end |
#respond(code, string_or_args = '') ⇒ TrueClass, FalseClass
Respond to the request
139 140 141 142 143 144 145 146 |
# File 'lib/carnivore-http/app.rb', line 139 def respond(code, string_or_args='') unless(@response_value) @response_value = Response.new(code, string_or_args) locker.synchronize{ responder.signal } else raise 'Response was already set!' end end |
#response(timeout = 5) ⇒ Response
Response to this request
152 153 154 155 156 157 158 159 160 161 162 163 |
# File 'lib/carnivore-http/app.rb', line 152 def response(timeout=5) unless(@response_value) begin Timeout.timeout(timeout) do locker.synchronize{ responder.wait(locker) } end rescue Timeout::Error @response_value = Response.new(:internal_server_error, 'Timeout waiting for response') end end @response_value end |