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/bin | |
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/bin')
-rwxr-xr-x | t/bin/content-md5-put | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/t/bin/content-md5-put b/t/bin/content-md5-put new file mode 100755 index 0000000..c35c92c --- /dev/null +++ b/t/bin/content-md5-put @@ -0,0 +1,36 @@ +#!/usr/bin/env ruby +# simple chunked HTTP PUT request generator (and just that), +# it reads stdin and writes to stdout so socat can write to a +# UNIX or TCP socket (or to another filter or file) along with +# a Content-MD5 trailer. +# -*- encoding: binary -*- +require 'digest/md5' +$stdout.sync = $stderr.sync = true +$stdout.binmode +$stdin.binmode + +bs = ENV['bs'] ? ENV['bs'].to_i : 4096 + +if ARGV.grep("--no-headers").empty? + $stdout.write( + "PUT / HTTP/1.1\r\n" \ + "Host: example.com\r\n" \ + "Transfer-Encoding: chunked\r\n" \ + "Trailer: Content-MD5\r\n" \ + "\r\n" + ) +end + +digest = Digest::MD5.new +if buf = $stdin.read(bs) + begin + digest.update(buf) + $stdout.write("%x\r\n" % [ buf.size ]) + $stdout.write(buf) + $stdout.write("\r\n") + end while $stdin.read(bs, buf) +end + +digest = [ digest.digest ].pack('m').strip +$stdout.write("0\r\n") +$stdout.write("Content-MD5: #{digest}\r\n\r\n") |