Class: Spider::HTTP::RackIO
- Inherits:
-
ControllerIO
- Object
- IO
- ControllerIO
- Spider::HTTP::RackIO
- Defined in:
- lib/spiderfw/http/adapters/rack.rb
Constant Summary
Constants inherited from ControllerIO
Instance Method Summary collapse
- #flush ⇒ Object
- #headers_sent? ⇒ Boolean
-
#initialize(response, controller_response, w, options = {}) ⇒ RackIO
constructor
A new instance of RackIO.
- #send_headers ⇒ Object
- #set_body_io(io) ⇒ Object
- #write(msg) ⇒ Object
Constructor Details
#initialize(response, controller_response, w, options = {}) ⇒ RackIO
23 24 25 26 27 28 29 30 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 23 def initialize(response, controller_response, w, ={}) @response = response @controller_response = controller_response @w = w @headers_sent = false @rack_thread = Thread.current = end |
Instance Method Details
#flush ⇒ Object
68 69 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 68 def flush end |
#headers_sent? ⇒ Boolean
53 54 55 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 53 def headers_sent? @headers_sent end |
#send_headers ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 37 def send_headers Spider::Logger.debug("---SENDING HEADERS----") @controller_response.prepare_headers @response[:status] = @controller_response.status @response[:headers] = {} @controller_response.headers.each do |key, val| if (val.is_a?(Array)) val.each{ |v| @response[:headers][key] = v.to_s } else @response[:headers][key] = val.to_s end end @headers_sent = true @rack_thread.run if [:multithread] end |
#set_body_io(io) ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 57 def set_body_io(io) return super if headers_sent? begin @response[:body].close rescue => exc end @response[:body] = io send_headers end |
#write(msg) ⇒ Object
32 33 34 35 |
# File 'lib/spiderfw/http/adapters/rack.rb', line 32 def write(msg) send_headers unless @headers_sent @w.write(msg) end |