From 02a072734906ac4c1ea77990207b84895ab4a7cb Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Tue, 9 Jun 2015 20:17:18 +0000 Subject: ensure body is closed during hijack Middlewares such as Rack::Lock (used by Rails) break badly unless the response body is closed on hijack, so we will close it to follow the lead of other popular Rack servers. While it's unclear if there's anybody using rack.hijack with unicorn, we'll try to emulate the behavior of other servers as much as possible. ref: https://github.com/ngauthier/tubesock/issues/10 --- t/hijack.ru | 3 ++- t/t0200-rack-hijack.sh | 7 +++++-- 2 files changed, 7 insertions(+), 3 deletions(-) (limited to 't') diff --git a/t/hijack.ru b/t/hijack.ru index fcb0b6d..4adec61 100644 --- a/t/hijack.ru +++ b/t/hijack.ru @@ -2,12 +2,13 @@ use Rack::Lint use Rack::ContentLength use Rack::ContentType, "text/plain" class DieIfUsed + @@n = 0 def each abort "body.each called after response hijack\n" end def close - abort "body.close called after response hijack\n" + warn "closed DieIfUsed #{@@n += 1}\n" end end run lambda { |env| diff --git a/t/t0200-rack-hijack.sh b/t/t0200-rack-hijack.sh index f772071..de3eb82 100755 --- a/t/t0200-rack-hijack.sh +++ b/t/t0200-rack-hijack.sh @@ -16,12 +16,15 @@ t_begin "check response hijack" && { test "xresponse.hijacked" = x"$(curl -sSfv http://$listen/hijack_res)" } -t_begin "killing succeeds" && { +t_begin "killing succeeds after hijack" && { kill $unicorn_pid } -t_begin "check stderr" && { +t_begin "check stderr for hijacked body close" && { check_stderr + grep 'closed DieIfUsed 1\>' $r_err + grep 'closed DieIfUsed 2\>' $r_err + ! grep 'closed DieIfUsed 3\>' $r_err } t_done -- cgit v1.2.3-24-ge0c7