diff options
Diffstat (limited to 'examples/echo.ru')
-rw-r--r-- | examples/echo.ru | 32 |
1 files changed, 32 insertions, 0 deletions
diff --git a/examples/echo.ru b/examples/echo.ru new file mode 100644 index 0000000..e13721a --- /dev/null +++ b/examples/echo.ru @@ -0,0 +1,32 @@ +#\-E none +# Example application that echoes read data back to the HTTP client. +# This emulates the old echo protocol people used to run. +# +# An example of using this in a client would be to run: +# curl -NT- http://host:port/ +# +# Then type random stuff in your terminal to watch it get echoed back! + +Unicorn::HttpRequest::DEFAULTS["unicorn.stream_input"] = true +class EchoBody + def initialize(input) + @input = input + end + + def each(&block) + while buf = @input.read(4096) + yield buf + end + self + end + + def close + @input = nil + end +end + +use Rack::Chunked +run lambda { |env| + [ 200, { 'Content-Type' => 'application/octet-stream' }, + EchoBody.new(env['rack.input']) ] +} |