Rainbows! 0.96.0 - range support
[rainbows.git] / t / content-md5.ru
blobe3ce4d3688a363a304f99e793c7e9f7ad6410be3
1 # SHA1 checksum generator
2 bs = ENV['bs'] ? ENV['bs'].to_i : 4096
3 require 'digest/md5'
4 use Rack::ContentLength
5 app = lambda do |env|
6   /\A100-continue\z/i =~ env['HTTP_EXPECT'] and
7     return [ 100, {}, [] ]
8   digest = Digest::MD5.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   expect = env['HTTP_CONTENT_MD5']
17   readed = [ digest.digest ].pack('m').strip
18   body = "expect=#{expect}\nreaded=#{readed}\n"
19   status = expect == readed ? 200 : 500
21   [ status, {'Content-Type' => 'text/plain'}, [ body ] ]
22 end
23 run app