diff options
author | Eric Wong <normalperson@yhbt.net> | 2010-07-19 10:09:56 +0000 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2010-07-19 17:04:26 -0700 |
commit | 1e6d3d19da2b62bfe7f8fd7827dcad3ee3fe9923 (patch) | |
tree | 5de875617e5cf3befb7c0ae9e1add9b2ee2f451e /lib/rainbows/dev_fd_response.rb | |
parent | cc18035c5105751a3e67a8e449ee0021fd313ea9 (diff) | |
download | rainbows-1e6d3d19da2b62bfe7f8fd7827dcad3ee3fe9923.tar.gz |
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.
Diffstat (limited to 'lib/rainbows/dev_fd_response.rb')
-rw-r--r-- | lib/rainbows/dev_fd_response.rb | 11 |
1 files changed, 6 insertions, 5 deletions
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 |