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/dev_fd_response.rb | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'lib/rainbows/dev_fd_response.rb') diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index c04d64f..451cad7 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -40,11 +40,12 @@ class Rainbows::DevFdResponse < Struct.new(:app) headers['Content-Length'] ||= st.size.to_s headers.delete('Transfer-Encoding') elsif st.pipe? || st.socket? # epoll-able things - if env['rainbows.autochunk'] - headers['Transfer-Encoding'] = 'chunked' - headers.delete('Content-Length') - else - headers['X-Rainbows-Autochunk'] = 'no' + unless headers['Content-Length'] + if env['rainbows.autochunk'] + headers['Transfer-Encoding'] = 'chunked' + else + headers['X-Rainbows-Autochunk'] = 'no' + end end # we need to make sure our pipe output is Fiber-compatible -- cgit v1.2.3-24-ge0c7