Force streaming input onto apps by default
[unicorn.git] / examples / echo.ru
blobebc4d9d6a41197e74bea4660ec503a7ff0997744
1 #\-E none
2 # Example application that echoes read data back to the HTTP client.
3 # This emulates the old echo protocol people used to run.
5 # An example of using this in a client would be to run:
6 #   curl -NT- http://host:port/
8 # Then type random stuff in your terminal to watch it get echoed back!
10 class EchoBody
11   def initialize(input)
12     @input = input
13   end
15   def each(&block)
16     while buf = @input.read(4096)
17       yield buf
18     end
19     self
20   end
22   def close
23     @input = nil
24   end
25 end
27 use Rack::Chunked
28 run lambda { |env|
29   [ 200, { 'Content-Type' => 'application/octet-stream' },
30     EchoBody.new(env['rack.input']) ]