Class: Rity::Request
- Inherits:
-
Object
- Object
- Rity::Request
- Includes:
- EM::Deferrable
- Defined in:
- lib/rity/request.rb
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
-
#env ⇒ Object
readonly
Returns the value of attribute env.
Instance Method Summary collapse
- #add_body_chunk(chunk) ⇒ Object
- #add_header(name, value) ⇒ Object
- #close_body ⇒ Object
-
#initialize(app, verb, uri) ⇒ Request
constructor
A new instance of Request.
- #postprocess(response) ⇒ Object
- #process ⇒ Object
Constructor Details
#initialize(app, verb, uri) ⇒ Request
Returns a new instance of Request.
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/rity/request.rb', line 11 def initialize(app, verb, uri) @app, @env = app, { "rack.input" => Body.new, "REQUEST_METHOD" => verb, "REQUEST_URI" => uri, "async.callback" => method(:postprocess), # "proxy.start" => &method(:proxy_start), # "proxy.callback" => &method(:proxy_start_reverse), # "proxy.start_reverse" => &method(:proxy_start_reverse), } end |
Instance Attribute Details
#app ⇒ Object (readonly)
Returns the value of attribute app.
9 10 11 |
# File 'lib/rity/request.rb', line 9 def app @app end |
#env ⇒ Object (readonly)
Returns the value of attribute env.
9 10 11 |
# File 'lib/rity/request.rb', line 9 def env @env end |
Instance Method Details
#add_body_chunk(chunk) ⇒ Object
28 29 30 |
# File 'lib/rity/request.rb', line 28 def add_body_chunk(chunk) env["rack.input"].write chunk end |
#add_header(name, value) ⇒ Object
23 24 25 26 |
# File 'lib/rity/request.rb', line 23 def add_header(name, value) key = "HTTP_" + name.upcase.gsub("-", "_") env[key] = value end |
#close_body ⇒ Object
32 33 34 |
# File 'lib/rity/request.rb', line 32 def close_body env["rack.input"].close_write end |
#postprocess(response) ⇒ Object
42 43 44 45 46 47 48 49 50 |
# File 'lib/rity/request.rb', line 42 def postprocess(response) return if response[0] < 0 env["stream.start"].call response[0..1] return if response[2] == Rack::STREAMING response[2].each {|chunk| env["stream.send"].call chunk } env["stream.close"].call end |
#process ⇒ Object
36 37 38 39 40 |
# File 'lib/rity/request.rb', line 36 def process Fiber.new { postprocess app.call(env) }.resume end |