From fc355db99bdbe72644e4691a7a107b6a29c77be6 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Wed, 19 Jan 2011 18:07:13 -0800 Subject: dev_fd_response: do not send chunks to 1.0 clients chunked Transfer-Encoding is only valid for HTTP/1.1 --- lib/rainbows/dev_fd_response.rb | 2 +- t/t0202-async-response-one-oh.sh | 56 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 1 deletion(-) create mode 100755 t/t0202-async-response-one-oh.sh diff --git a/lib/rainbows/dev_fd_response.rb b/lib/rainbows/dev_fd_response.rb index 1d50a2c..a42697d 100644 --- a/lib/rainbows/dev_fd_response.rb +++ b/lib/rainbows/dev_fd_response.rb @@ -48,7 +48,7 @@ class Rainbows::DevFdResponse < Struct.new(:app) headers.delete('Transfer-Encoding') elsif st.pipe? || st.socket? # epoll-able things unless headers.include?('Content-Length') - if env['rainbows.autochunk'] + if env['rainbows.autochunk'] && "HTTP/1.0" != env["HTTP_VERSION"] headers['Transfer-Encoding'] = 'chunked' else env['rainbows.autochunk'] = false diff --git a/t/t0202-async-response-one-oh.sh b/t/t0202-async-response-one-oh.sh new file mode 100755 index 0000000..0d833ca --- /dev/null +++ b/t/t0202-async-response-one-oh.sh @@ -0,0 +1,56 @@ +#!/bin/sh +CONFIG_RU=${CONFIG_RU-'async-response.ru'} +. ./test-lib.sh + +skip_models Base WriterThreadPool WriterThreadSpawn + +t_plan 6 "async HTTP/1.0 response for $model" + +t_begin "setup and start" && { + rainbows_setup + rtmpfiles a b c a_err b_err c_err + # can't load Rack::Lint here since it'll cause Rev to slurp + rainbows -E none -D $CONFIG_RU -c $unicorn_config + rainbows_wait_start +} + +t_begin "send async requests off in parallel" && { + t0=$(date +%s) + curl="curl -0 --no-buffer -vsSf http://$listen/" + ( $curl 2>> $a_err | utee $a) & + ( $curl 2>> $b_err | utee $b) & + ( $curl 2>> $c_err | utee $c) & + wait + t1=$(date +%s) +} + +t_begin "ensure elapsed requests were processed in parallel" && { + elapsed=$(( $t1 - $t0 )) + echo "elapsed=$elapsed < 30" + test $elapsed -lt 30 +} + +t_begin "termination signal sent" && { + kill $rainbows_pid +} + +dbgcat a +dbgcat b +dbgcat c +dbgcat a_err + +t_begin "no errors from curl" && { + if grep -i Transfer-Encoding $a_err $b_err $c_err + then + die "Unexpected Transfer-Encoding: header" + fi + for i in $a_err $b_err $c_err + do + grep 'Connection: close' $i + done +} + +dbgcat r_err +t_begin "no errors in stderr" && check_stderr + +t_done -- cgit v1.2.3-24-ge0c7