lib/rainbows/http_response.rb in rainbows-0.94.0 vs lib/rainbows/http_response.rb in rainbows-0.95.0
- old
+ new
@@ -1,38 +1,27 @@
# -*- encoding: binary -*-
-require 'time'
+# :enddoc:
+# deprecated, use Rainbows::Response instead
+# Cramp 0.11 relies on this, and is only activated by Cramp
+if defined?(Cramp) && defined?(Rainbows::EventMachine::Client)
+ class Rainbows::HttpResponse
+ class << self
+ include Rainbows::Response
+ alias write write_response
+ end
+ end
-module Rainbows
-
- class HttpResponse < ::Unicorn::HttpResponse
-
- def self.header_string(status, headers, out)
- status = CODES[status.to_i] || status
-
- headers.each do |key, value|
- next if %r{\AX-Rainbows-}i =~ key
- next if SKIP.include?(key.downcase)
- if value =~ /\n/
- # avoiding blank, key-only cookies with /\n+/
- out.concat(value.split(/\n+/).map! { |v| "#{key}: #{v}\r\n" })
- else
- out << "#{key}: #{value}\r\n"
- end
+ module Rainbows::EventMachine::CrampSocket
+ def write_header(_, response, out)
+ if websocket?
+ write web_socket_upgrade_data
+ web_socket_handshake!
+ out = nil # disable response headers
end
-
- "HTTP/1.1 #{status}\r\n" \
- "Date: #{Time.now.httpdate}\r\n" \
- "Status: #{status}\r\n" \
- "#{out.join('')}\r\n"
+ super(self, response, out)
end
+ end
- def self.write(socket, rack_response, out = [])
- status, headers, body = rack_response
- out.instance_of?(Array) and
- socket.write(header_string(status, headers, out))
-
- body.each { |chunk| socket.write(chunk) }
- ensure
- body.respond_to?(:close) and body.close
- end
+ class Rainbows::EventMachine::Client
+ include Rainbows::EventMachine::CrampSocket
end
end