diff options
Diffstat (limited to 'lib/rainbows/rev')
-rw-r--r-- | lib/rainbows/rev/client.rb | 12 | ||||
-rw-r--r-- | lib/rainbows/rev/sendfile.rb | 5 |
2 files changed, 12 insertions, 5 deletions
diff --git a/lib/rainbows/rev/client.rb b/lib/rainbows/rev/client.rb index 502615e..2242c18 100644 --- a/lib/rainbows/rev/client.rb +++ b/lib/rainbows/rev/client.rb @@ -80,15 +80,21 @@ module Rainbows st = io.stat if st.file? - write(response_header(status, headers)) if headers - return defer_body(F.new(0, io, body)) + offset, count = 0, st.size + if headers + if range = parse_range(@env, status, headers) + status, offset, count = range + end + write(response_header(status, headers)) + end + return defer_body(F.new(offset, count, io, body)) elsif st.socket? || st.pipe? return stream_response(status, headers, io, body) end # char or block device... WTF? fall through to body.each end write(response_header(status, headers)) if headers - write_body_each(self, body) + write_body_each(self, body, nil) end def app_call diff --git a/lib/rainbows/rev/sendfile.rb b/lib/rainbows/rev/sendfile.rb index 9f421f1..42368a1 100644 --- a/lib/rainbows/rev/sendfile.rb +++ b/lib/rainbows/rev/sendfile.rb @@ -2,8 +2,9 @@ # :enddoc: module Rainbows::Rev::Sendfile if IO.method_defined?(:sendfile_nonblock) - def rev_sendfile(body) - body.offset += @_io.sendfile_nonblock(body, body.offset, 0x10000) + def rev_sendfile(sf) # +sf+ is a Rainbows::StreamFile object + sf.offset += (n = @_io.sendfile_nonblock(sf, sf.offset, sf.count)) + 0 == (sf.count -= n) and raise EOFError enable_write_watcher rescue Errno::EAGAIN enable_write_watcher |