README: reference yahns
[zbatery.git] / t / sha1-random-size.ru
blobf86d017c21be7baaa420079b25c290ed89c5675a
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   if buf = input.read(rand(cap))
11     begin
12       raise "#{buf.size} > #{cap}" if buf.size > cap
13       digest.update(buf)
14     end while input.read(rand(cap), buf)
15   end
17   [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ]
18 end
19 run app