diff options
author | Eric Wong <e@80x24.org> | 2015-06-30 00:45:38 +0000 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2015-06-30 02:46:02 +0000 |
commit | baaebed4d7c50a3f14fbada767bada6fc2f0c8b5 (patch) | |
tree | dd3838815bfd320f65244a19ae15af14a5dbdc73 /lib/yahns | |
parent | dbb0db4cc9ba99e975d7a61e99756c38d6f68a79 (diff) | |
download | yahns-baaebed4d7c50a3f14fbada767bada6fc2f0c8b5.tar.gz |
Rack::Utils::HTTP_STATUS_CODES may be altered by the underlying application, allow changes to that to be reflected in our responses and do not rely on the Unicorn::HttpResponse::CODES hash which will probably go away soon.
Diffstat (limited to 'lib/yahns')
-rw-r--r-- | lib/yahns/http_response.rb | 8 | ||||
-rw-r--r-- | lib/yahns/proxy_http_response.rb | 11 |
2 files changed, 11 insertions, 8 deletions
diff --git a/lib/yahns/http_response.rb b/lib/yahns/http_response.rb index fabd4b7..b70491d 100644 --- a/lib/yahns/http_response.rb +++ b/lib/yahns/http_response.rb @@ -59,7 +59,7 @@ module Yahns::HttpResponse # :nodoc: end def err_response(code) - "#{response_start}#{CODES[code]}\r\n\r\n" + "#{response_start}#{code} #{Rack::Utils::HTTP_STATUS_CODES[code]}\r\n\r\n" end def response_header_blocked(ret, header, body, alive, offset, count) @@ -130,7 +130,6 @@ module Yahns::HttpResponse # :nodoc: # writes the rack_response to socket as an HTTP response # returns :wait_readable, :wait_writable, :forget, or nil def http_response_write(status, headers, body) - status = CODES[status.to_i] || status offset = 0 count = hijack = nil k = self.class @@ -138,7 +137,10 @@ module Yahns::HttpResponse # :nodoc: flags = MSG_DONTWAIT if @hs.headers? - buf = "#{response_start}#{status}\r\nDate: #{httpdate}\r\n" + code = status.to_i + msg = Rack::Utils::HTTP_STATUS_CODES[code] + buf = "#{response_start}#{msg ? %Q(#{code} #{msg}) : status}\r\n" \ + "Date: #{httpdate}\r\n" headers.each do |key, value| case key when %r{\ADate\z}i diff --git a/lib/yahns/proxy_http_response.rb b/lib/yahns/proxy_http_response.rb index cbdce6f..61989c2 100644 --- a/lib/yahns/proxy_http_response.rb +++ b/lib/yahns/proxy_http_response.rb @@ -38,7 +38,8 @@ module Yahns::HttpResponse # :nodoc: end # try to write something, but don't care if we fail Integer === code and - kgio_trywrite("HTTP/1.1 #{CODES[code]}\r\n\r\n") rescue nil + kgio_trywrite("HTTP/1.1 #{code} #{ + Rack::Utils::HTTP_STATUS_CODES[code]}\r\n\r\n") rescue nil shutdown rescue nil req_res.shutdown rescue nil @@ -59,16 +60,16 @@ module Yahns::HttpResponse # :nodoc: # returns nil if completely done def proxy_response_start(res, tip, kcar, req_res) status, headers = res - si = status.to_i - status = CODES[si] || status + code = status.to_i + msg = Rack::Utils::HTTP_STATUS_CODES[code] env = @hs.env - have_body = !Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(si) && + have_body = !Rack::Utils::STATUS_WITH_NO_ENTITY_BODY.include?(code) && env[REQUEST_METHOD] != HEAD flags = MSG_DONTWAIT alive = @hs.next? && self.class.persistent_connections response_headers = env['yahns.proxy_pass.response_headers'] - res = "HTTP/1.1 #{status}\r\n" + res = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n" headers.each do |key,value| # n.b.: headers is an Array of 2-element Arrays case key when /\A(?:Connection|Keep-Alive)\z/i |