diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-10-14 17:39:08 -0700 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-10-14 17:39:51 -0700 |
commit | 0a47b9209b6c677ad03ad2075f671883ca2b7474 (patch) | |
tree | 2c2fc415f527c9f3f8b96912b20a76bbe0420647 /t/content-md5.ru | |
parent | a42148fe4d62f812bc57418daecdb95f3c4d18cd (diff) | |
download | rainbows-0a47b9209b6c677ad03ad2075f671883ca2b7474.tar.gz |
There is no TeeInput (streaming request body) support, yet, as that does not seem fun nor easy to do (or even possible without using Threads or Fibers or something to save/restore the stack...)
Diffstat (limited to 't/content-md5.ru')
-rw-r--r-- | t/content-md5.ru | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/t/content-md5.ru b/t/content-md5.ru new file mode 100644 index 0000000..e3ce4d3 --- /dev/null +++ b/t/content-md5.ru @@ -0,0 +1,23 @@ +# SHA1 checksum generator +bs = ENV['bs'] ? ENV['bs'].to_i : 4096 +require 'digest/md5' +use Rack::ContentLength +app = lambda do |env| + /\A100-continue\z/i =~ env['HTTP_EXPECT'] and + return [ 100, {}, [] ] + digest = Digest::MD5.new + input = env['rack.input'] + if buf = input.read(bs) + begin + digest.update(buf) + end while input.read(bs, buf) + end + + expect = env['HTTP_CONTENT_MD5'] + readed = [ digest.digest ].pack('m').strip + body = "expect=#{expect}\nreaded=#{readed}\n" + status = expect == readed ? 200 : 500 + + [ status, {'Content-Type' => 'text/plain'}, [ body ] ] +end +run app |