TODO: documentation needs work, so document it :P
[rainbows.git] / t / sha1.ru
blobb5239770ada218fad15fa75af34969eb9a361ad9
1 # SHA1 checksum generator
2 bs = ENV['bs'] ? ENV['bs'].to_i : 16384
3 require 'digest/sha1'
4 use Rack::ContentLength
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(bs)
11     begin
12       digest.update(buf)
13     end while input.read(bs, buf)
14   end
16   [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ]
17 end
18 run app