From b6dcf1343a379f0fb5de5cc551dbbf85da2b4cdf Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 18 Apr 2010 21:24:07 -0700 Subject: rev/deferred_response: cleanup and simplification We can use the new HttpResponse.header_string method now instead of writing an empty body. --- lib/rainbows/rev/deferred_response.rb | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) (limited to 'lib') diff --git a/lib/rainbows/rev/deferred_response.rb b/lib/rainbows/rev/deferred_response.rb index b69c7be..dd7a229 100644 --- a/lib/rainbows/rev/deferred_response.rb +++ b/lib/rainbows/rev/deferred_response.rb @@ -10,9 +10,13 @@ module Rainbows G = Rainbows::G HH = Rack::Utils::HeaderHash - def self.defer!(client, response, out) - body = response.last - headers = HH.new(response[1]) + def self.write(client, response, out) + status, headers, body = response + + body.respond_to?(:to_path) or + return HttpResponse.write(client, response, out) + + headers = HH.new(headers) # to_io is not part of the Rack spec, but make an exception # here since we can't get here without checking to_path first @@ -39,16 +43,11 @@ module Rainbows headers.delete('Transfer-Encoding') headers['Content-Length'] ||= st.size.to_s else # char/block device, directory, whatever... nobody cares - return response + return HttpResponse.write(client, response, out) end client.defer_body(io, out) - [ response.first, headers.to_hash, [] ] - end - - def self.write(client, response, out) - response.last.respond_to?(:to_path) and - response = defer!(client, response, out) - HttpResponse.write(client, response, out) + out.nil? or + client.write(HttpResponse.header_string(status, headers.to_hash, out)) end def initialize(io, client, do_chunk, body) -- cgit v1.2.3-24-ge0c7