From e21939d776673b2f8887adf7a5c64812b7d2e98e Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Thu, 30 Dec 2010 08:33:15 +0000 Subject: globally refactor Range handling for responses Rack::Utils::HeaderHash is still very expensive in Rack 1.2, especially for simple things that we want to run as fast as possible with minimal interference. HeaderHash is unnecessary for most requests that do not send Content-Range in responses. --- lib/rainbows/event_machine/client.rb | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) (limited to 'lib/rainbows/event_machine/client.rb') diff --git a/lib/rainbows/event_machine/client.rb b/lib/rainbows/event_machine/client.rb index 6863be0..2fc9d03 100644 --- a/lib/rainbows/event_machine/client.rb +++ b/lib/rainbows/event_machine/client.rb @@ -58,27 +58,20 @@ class Rainbows::EventMachine::Client < EM::Connection end end + # don't change this method signature, "async.callback" relies on it def em_write_response(response, alive = false) status, headers, body = response - if @hp.headers? - headers = HH.new(headers) - headers[CONNECTION] = alive ? KEEP_ALIVE : CLOSE - else - headers = nil - end if body.respond_to?(:errback) && body.respond_to?(:callback) @body = body body.callback { quit } body.errback { quit } - # async response, this could be a trickle as is in comet-style apps - headers[CONNECTION] = CLOSE if headers alive = true elsif body.respond_to?(:to_path) st = File.stat(path = body.to_path) if st.file? - write(response_header(status, headers)) if headers + write_headers(status, headers, alive) @body = stream_file_data(path) @body.errback do body.close if body.respond_to?(:close) @@ -92,16 +85,14 @@ class Rainbows::EventMachine::Client < EM::Connection return elsif st.socket? || st.pipe? io = body_to_io(@body = body) - chunk = stream_response_headers(status, headers) if headers + chunk = stream_response_headers(status, headers, alive) m = chunk ? Rainbows::EventMachine::ResponseChunkPipe : Rainbows::EventMachine::ResponsePipe return EM.watch(io, m, self).notify_readable = true end # char or block device... WTF? fall through to body.each end - - write(response_header(status, headers)) if headers - write_body_each(self, body) + write_response(status, headers, body, alive) quit unless alive end -- cgit v1.2.3-24-ge0c7