unicorn 4.6.0pre1 - hijacking support
[unicorn.git] / examples / echo.ru
blob14908c5c9d334b240030c12abdc6f9b4af2491f5
1 #\-E none
3 # Example application that echoes read data back to the HTTP client.
4 # This emulates the old echo protocol people used to run.
6 # An example of using this in a client would be to run:
7 #   curl --no-buffer -T- http://host:port/
9 # Then type random stuff in your terminal to watch it get echoed back!
11 class EchoBody < Struct.new(:input)
13   def each(&block)
14     while buf = input.read(4096)
15       yield buf
16     end
17     self
18   end
20 end
22 use Rack::Chunked
23 run lambda { |env|
24   /\A100-continue\z/i =~ env['HTTP_EXPECT'] and return [100, {}, []]
25   [ 200, { 'Content-Type' => 'application/octet-stream' },
26     EchoBody.new(env['rack.input']) ]