From 13a09dec6c029e01e8d959b0bf0feb94d72ae32d Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sat, 2 Nov 2013 01:00:00 +0000 Subject: account for truncated/expanded static files When running a static file server, we must account for filesystem activity outside of our control where files may grow/shrink as they're being served. For truncated files, we must abort any persistent connections downloading a truncated file to avoid confusing clients because the Content-Length header was already set to the big value. We also must ensure (we already did so before this commit, this just adds a test for it) we do not send additional data when a file grows on us after we've started sending the response. --- lib/yahns/wbuf_common.rb | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/yahns/wbuf_common.rb b/lib/yahns/wbuf_common.rb index cfafaa2..b3a4502 100644 --- a/lib/yahns/wbuf_common.rb +++ b/lib/yahns/wbuf_common.rb @@ -14,8 +14,16 @@ module Yahns::WbufCommon # :nodoc: @sf_offset += rv # keep going otherwise when :wait_writable, :wait_readable return rv + when nil + # response got truncated, drop the connection + # this may happens when using Rack::File or similar, we can't + # keep the connection alive because we already sent our Content-Length + # header the client would be confused. + @wbuf_persist = false + return wbuf_close(client) else - raise "BUG: #{rv.nil? ? "EOF" : rv.inspect} on tmpio=#{@tmpio.inspect} " \ + raise "BUG: rv=#{rv.inspect} " \ + "on tmpio=#{@tmpio.inspect} " \ "sf_offset=#@sf_offset sf_count=#@sf_count" end while true end -- cgit v1.2.3-24-ge0c7