From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on dcvr.yhbt.net X-Spam-Level: X-Spam-ASN: X-Spam-Status: No, score=-2.9 required=3.0 tests=ALL_TRUSTED,BAYES_00 shortcircuit=no autolearn=unavailable version=3.3.2 X-Original-To: yahns-public@yhbt.net Received: from localhost (dcvr.yhbt.net [127.0.0.1]) by dcvr.yhbt.net (Postfix) with ESMTP id ADE1563383B; Tue, 30 Jun 2015 03:02:03 +0000 (UTC) From: Eric Wong To: yahns-public@yhbt.net Cc: e@80x24.org Subject: [PATCH 1/3] generate response status strings dynamically Date: Tue, 30 Jun 2015 03:01:51 +0000 Message-Id: <1435633313-30223-2-git-send-email-e@80x24.org> In-Reply-To: <1435633313-30223-1-git-send-email-e@80x24.org> References: <1435633313-30223-1-git-send-email-e@80x24.org> List-Id: 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. --- lib/yahns/http_response.rb | 8 +++++--- 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 -- EW