From 1e6d3d19da2b62bfe7f8fd7827dcad3ee3fe9923 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Mon, 19 Jul 2010 10:09:56 +0000 Subject: rev + em: more easily allow Content-Length in pipe responses If a response proxying a pipe (or socket) includes a Content-Length, do not attempt to outsmart the application and just use the given Content-Length. This helps avoid exposing applications to weird internals such as env["rainbows.autochunk"] and X-Rainbows-* response headers. --- lib/rainbows/ev_core.rb | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'lib/rainbows/ev_core.rb') diff --git a/lib/rainbows/ev_core.rb b/lib/rainbows/ev_core.rb index 5ca693b..dbcdeba 100644 --- a/lib/rainbows/ev_core.rb +++ b/lib/rainbows/ev_core.rb @@ -6,6 +6,7 @@ module Rainbows module EvCore include Unicorn include Rainbows::Const + include Rainbows::Response G = Rainbows::G NULL_IO = Unicorn::HttpRequest::NULL_IO @@ -33,6 +34,19 @@ module Rainbows quit end + # returns whether to enable response chunking for autochunk models + def stream_response_headers(status, headers) + if headers['Content-Length'] + rv = false + else + rv = !!(headers['Transfer-Encoding'] =~ %r{\Achunked\z}i) + rv = false if headers.delete('X-Rainbows-Autochunk') == 'no' + end + headers[CONNECTION] = CLOSE # TODO: allow keep-alive + write(response_header(status, headers)) + rv + end + # TeeInput doesn't map too well to this right now... def on_read(data) case @state -- cgit v1.2.3-24-ge0c7