diff options
author | Eric Wong <normalperson@yhbt.net> | 2009-11-08 01:57:14 -0800 |
---|---|---|
committer | Eric Wong <normalperson@yhbt.net> | 2009-11-08 02:49:14 -0800 |
commit | 8cd6f4d94503a568501b6e24bb785a8e002720c9 (patch) | |
tree | 82c6c2df9ec84038e55e08444a2b505f076ac031 /t/sha1-random-size.ru | |
parent | b4f1271320d38e83141dbb38463c3a368661aef7 (diff) | |
download | rainbows-8cd6f4d94503a568501b6e24bb785a8e002720c9.tar.gz |
Explicitly requested short reads may cause too much data to be returned, which would be bad and potentially break the application. We need to ensure proper IO#readpartial-like semantics in both of these models.
Diffstat (limited to 't/sha1-random-size.ru')
-rw-r--r-- | t/sha1-random-size.ru | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/t/sha1-random-size.ru b/t/sha1-random-size.ru new file mode 100644 index 0000000..f86d017 --- /dev/null +++ b/t/sha1-random-size.ru @@ -0,0 +1,19 @@ +# SHA1 checksum generator +require 'digest/sha1' +use Rack::ContentLength +cap = 16384 +app = lambda do |env| + /\A100-continue\z/i =~ env['HTTP_EXPECT'] and + return [ 100, {}, [] ] + digest = Digest::SHA1.new + input = env['rack.input'] + if buf = input.read(rand(cap)) + begin + raise "#{buf.size} > #{cap}" if buf.size > cap + digest.update(buf) + end while input.read(rand(cap), buf) + end + + [ 200, {'Content-Type' => 'text/plain'}, [ digest.hexdigest << "\n" ] ] +end +run app |