1 # -*- encoding: binary -*-
7 class HttpResponse < ::Unicorn::HttpResponse
9 def self.write(socket, rack_response, out = [])
10 status, headers, body = rack_response
13 status = CODES[status.to_i] || status
15 headers.each do |key, value|
16 next if %r{\AX-Rainbows-}i =~ key
17 next if SKIP.include?(key.downcase)
19 out.concat(value.split(/\n/).map! { |v| "#{key}: #{v}\r\n" })
21 out << "#{key}: #{value}\r\n"
25 socket.write("HTTP/1.1 #{status}\r\n" \
26 "Date: #{Time.now.httpdate}\r\n" \
27 "Status: #{status}\r\n" \
28 "#{out.join('')}\r\n")
31 body.each { |chunk| socket.write(chunk) }
33 body.respond_to?(:close) and body.close rescue nil