From a80ba923659a4287f05a8c69fe2c5ad8b65d28f7 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 15 Nov 2009 12:09:23 -0800 Subject: tee_input: expand client error handling First move it to a separate method, this allows subclasses to reuse our error handler. Additionally, capture HttpParserError as well since backtraces are worthless when a client sends us a bad request, too. --- lib/unicorn/tee_input.rb | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) (limited to 'lib/unicorn/tee_input.rb') diff --git a/lib/unicorn/tee_input.rb b/lib/unicorn/tee_input.rb index 01717ce..18ce44b 100644 --- a/lib/unicorn/tee_input.rb +++ b/lib/unicorn/tee_input.rb @@ -123,6 +123,21 @@ module Unicorn private + def client_error(e) + case e + when EOFError + # in case client only did a premature shutdown(SHUT_WR) + # we do support clients that shutdown(SHUT_WR) after the + # _entire_ request has been sent, and those will not have + # raised EOFError on us. + socket.close if socket + raise ClientShutdown, "bytes_read=#{@tmp.size}", [] + when HttpParserError + e.set_backtrace([]) + raise e + end + end + # tees off a +length+ chunk of data from the input into the IO # backing store as well as returning it. +dst+ must be specified. # returns nil if reading from the input returns nil @@ -135,13 +150,8 @@ module Unicorn end end finalize_input - rescue EOFError - # in case client only did a premature shutdown(SHUT_WR) - # we do support clients that shutdown(SHUT_WR) after the - # _entire_ request has been sent, and those will not have - # raised EOFError on us. - socket.close if socket - raise ClientShutdown, "bytes_read=#{@tmp.size}", [] + rescue => e + client_error(e) end def finalize_input -- cgit v1.2.3-24-ge0c7