From: Eric Wong <e@80x24.org> To: rainbows-public@bogomips.org Subject: [PATCH 3/5] reflect changes in Rack::Utils::HTTP_STATUS_CODES Date: Sat, 14 Nov 2015 02:47:23 +0000 Message-ID: <20151114024725.24139-4-e@80x24.org> (raw) In-Reply-To: <20151114024725.24139-1-e@80x24.org> Applications may want to alter the message associated with HTTP status codes in Rack::Utils::HTTP_STATUS_CODES. Avoid memoizing status lines ahead-of-time Note: this introduces a minor performance regression, but ought to be unnoticeable unless you're running "Hello world"-type apps. --- lib/rainbows/response.rb | 5 +++-- lib/rainbows/stream_response_epoll.rb | 6 +++--- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/rainbows/response.rb b/lib/rainbows/response.rb index db14ee4..a661ab6 100644 --- a/lib/rainbows/response.rb +++ b/lib/rainbows/response.rb @@ -40,8 +40,9 @@ module Rainbows::Response def write_headers(status, headers, alive, body) @hp.headers? or return body hijack = nil - status = CODES[status.to_i] || status - buf = "HTTP/1.1 #{status}\r\n" \ + code = status.to_i + msg = Rack::Utils::HTTP_STATUS_CODES[code] + buf = "HTTP/1.1 #{msg ? %Q(#{code} #{msg}) : status}\r\n" \ "Date: #{httpdate}\r\n" headers.each do |key, value| case key diff --git a/lib/rainbows/stream_response_epoll.rb b/lib/rainbows/stream_response_epoll.rb index c0d90a4..1f32dcc 100644 --- a/lib/rainbows/stream_response_epoll.rb +++ b/lib/rainbows/stream_response_epoll.rb @@ -20,18 +20,18 @@ require "raindrops" # * sleepy_penguin 3.0.1 or later module Rainbows::StreamResponseEpoll # :stopdoc: - CODES = Unicorn::HttpResponse::CODES HEADER_END = "X-Accel-Buffering: no\r\n\r\n" autoload :Client, "rainbows/stream_response_epoll/client" def http_response_write(socket, status, headers, body) - status = CODES[status.to_i] || status hijack = ep_client = false if headers # don't set extra headers here, this is only intended for # consuming by nginx. - buf = "HTTP/1.0 #{status}\r\n" + code = status.to_i + msg = Rack::Utils::HTTP_STATUS_CODES[code] + buf = "HTTP/1.0 #{msg ? %Q(#{code} #{msg}) : status}\r\n" headers.each do |key, value| case key when "rack.hijack" -- EW
next prev parent reply index Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top 2015-11-14 2:47 [WIP 0/5] updates for unicorn 5 internal changes Eric Wong 2015-11-14 2:47 ` [PATCH 1/5] http_parser: handle keepalive_requests internally Eric Wong 2015-11-14 2:47 ` [PATCH 2/5] kill the moronic Status: header Eric Wong 2015-11-14 2:47 ` Eric Wong [this message] 2015-11-14 2:47 ` [PATCH 4/5] reduce constant lookup dependencies Eric Wong 2015-11-14 2:47 ` [PATCH 5/5] http_parser: workaround hijack changes in unicorn 5 Eric Wong
Reply instructions: You may reply publically to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style List information: http://bogomips.org/rainbows/ * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20151114024725.24139-4-e@80x24.org \ --to=e@80x24.org \ --cc=rainbows-public@bogomips.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Rainbows! Rack HTTP server user/dev discussion Archives are clonable: git clone --mirror http://bogomips.org/rainbows-public git clone --mirror http://ou63pmih66umazou.onion/rainbows-public Example config snippet for mirrors Newsgroups are available over NNTP: nntp://news.public-inbox.org/inbox.comp.lang.ruby.rainbows nntp://ou63pmih66umazou.onion/inbox.comp.lang.ruby.rainbows note: .onion URLs require Tor: https://www.torproject.org/ AGPL code for this site: git clone https://public-inbox.org/public-inbox.git