From 7b01d94dd9287ac402d91451f1e93c9faaf913c4 Mon Sep 17 00:00:00 2001 From: Eric Wong Date: Sun, 18 Oct 2009 15:59:29 -0700 Subject: rev: async response bodies with DevFdResponse middleware This new middleware should be a no-op for non-Rev concurrency models (or by explicitly setting env['rainbows.autochunk'] to false). Setting env['rainbows.autochunk'] to true (the default when Rev is used) allows (e)poll-able IO objects (sockets, pipes) to be sent asynchronously after app.call(env) returns. This also has a fortunate side effect of introducing a code path which allows large, static files to be sent without slurping them into a Rev IO::Buffer, too. This new change works even without the DevFdResponse middleware, so you won't have to reconfigure your app. This lets us epoll on response bodies that come in from a pipe or even a socket and send them either straight through or with chunked encoding. --- t/large-file-response.ru | 13 +++++++++++++ 1 file changed, 13 insertions(+) create mode 100644 t/large-file-response.ru (limited to 't/large-file-response.ru') diff --git a/t/large-file-response.ru b/t/large-file-response.ru new file mode 100644 index 0000000..90dc6c5 --- /dev/null +++ b/t/large-file-response.ru @@ -0,0 +1,13 @@ +# lib-large-file-response will stop running if we're not on Linux here +use Rack::ContentLength +use Rack::ContentType +map "/rss" do + run lambda { |env| + # on Linux, this is in kilobytes + ::File.read("/proc/self/status") =~ /^VmRSS:\s+(\d+)/ + [ 200, {}, [ ($1.to_i * 1024).to_s ] ] + } +end +map "/" do + run Rack::File.new(Dir.pwd) +end -- cgit v1.2.3-24-ge0c7