Sha256: 55e09698f0f2113d0b861c0719512413455e805f93ddf28812786bec836f0785

Contents?: true

Size: 906 Bytes

Versions: 3

Compression:

Stored size: 906 Bytes

Contents

# -*- encoding: binary -*-
require 'time'
require 'rainbows'

module Rainbows

  class HttpResponse < ::Unicorn::HttpResponse

    def self.write(socket, rack_response, out = [])
      status, headers, body = rack_response

      if Array === out
        status = CODES[status.to_i] || status

        headers.each do |key, value|
          next if SKIP.include?(key.downcase)
          if value =~ /\n/
            out.concat(value.split(/\n/).map! { |v| "#{key}: #{v}\r\n" })
          else
            out << "#{key}: #{value}\r\n"
          end
        end

        socket.write("HTTP/1.1 #{status}\r\n" \
                     "Date: #{Time.now.httpdate}\r\n" \
                     "Status: #{status}\r\n" \
                     "#{out.join('')}\r\n")
      end

      body.each { |chunk| socket.write(chunk) }
      ensure
        body.respond_to?(:close) and body.close rescue nil
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
rainbows-0.2.0 lib/rainbows/http_response.rb
rainbows-0.1.1 lib/rainbows/http_response.rb
rainbows-0.1.0 lib/rainbows/http_response.rb