t/lib.perl: fix Perl integration tests w/o installation
[unicorn.git] / examples / echo.ru
blob453a5e6b51ab198aa9050ac1378d5be62b253493
1 #\-E none
2 # frozen_string_literal: false
4 # Example application that echoes read data back to the HTTP client.
5 # This emulates the old echo protocol people used to run.
7 # An example of using this in a client would be to run:
8 #   curl --no-buffer -T- http://host:port/
10 # Then type random stuff in your terminal to watch it get echoed back!
12 class EchoBody < Struct.new(:input)
14   def each(&block)
15     while buf = input.read(4096)
16       yield buf
17     end
18     self
19   end
21 end
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']) ]