unicorn.git  about / heads / tags
Rack HTTP server for Unix and fast clients
blob 322fe94819d1b3fa869de19ce586875cde3354b0 648 bytes (raw)
$ git show v0.9.0:examples/echo.ru	# shows this blob on the CLI

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
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 --no-buffer -T- http://host:port/
#
# Then type random stuff in your terminal to watch it get echoed back!

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']) ]
}

git clone https://yhbt.net/unicorn.git