lib/rainbows/revactor/tee_input.rb in rainbows-0.5.0 vs lib/rainbows/revactor/tee_input.rb in rainbows-0.6.0

- old
+ new

@@ -19,22 +19,30 @@ # 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 def tee(length, dst) unless parser.body_eof? - begin - if parser.filter_body(dst, buf << socket.read).nil? - @tmp.write(dst) - return dst + if parser.filter_body(dst, buf << socket.read).nil? + @tmp.write(dst) + diff = dst.size - length + if diff > 0 + dst.replace(dst[0,length]) + @tmp.seek(-diff, IO::SEEK_CUR) end - rescue EOFError + return dst end end finalize_input + rescue => e + client_error(e) end def finalize_input while parser.trailers(req, buf).nil? + # Don't worry about raising ClientShutdown here on EOFError, tee() + # will catch EOFError when app is processing it, otherwise in + # initialize we never get any chance to enter the app so the + # EOFError will just get trapped by Unicorn and not the Rack app buf << socket.read end self.socket = nil end