support for Rack hijack in request and response
[unicorn.git] / t / rack-input-tests.ru
blob8c35630790d0eef594d221b7a4dbecf171ea2b45
1 # SHA1 checksum generator
2 require 'digest/sha1'
3 use Rack::ContentLength
4 cap = 16384
5 app = lambda do |env|
6   /\A100-continue\z/i =~ env['HTTP_EXPECT'] and
7     return [ 100, {}, [] ]
8   digest = Digest::SHA1.new
9   input = env['rack.input']
10   input.size if env["PATH_INFO"] == "/size_first"
11   input.rewind if env["PATH_INFO"] == "/rewind_first"
12   if buf = input.read(rand(cap))
13     begin
14       raise "#{buf.size} > #{cap}" if buf.size > cap
15       digest.update(buf)
16     end while input.read(rand(cap), buf)
17   end
19   [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ]
20 end
21 run app