tests: rack.input trailer tests for all models
[rainbows.git] / t / bin / content-md5-put
blob4f02a855b25a9e51f9c58cd1b8ee5edfe97459dc
1 #!/usr/bin/env ruby
2 # simple chunked HTTP PUT request generator (and just that),
3 # it reads stdin and writes to stdout so socat can write to a
4 # UNIX or TCP socket (or to another filter or file) along with
5 # a Content-MD5 trailer.
6 # -*- encoding: binary -*-
7 require 'digest/md5'
8 $stdout.sync = $stderr.sync = true
9 $stdout.binmode
10 $stdin.binmode
12 bs = ENV['bs'] ? ENV['bs'].to_i : 4096
14 if ARGV.grep("--no-headers").empty?
15 $stdout.write(
16 "PUT / HTTP/1.1\r\n" \
17 "Host: example.com\r\n" \
18 "Transfer-Encoding: chunked\r\n" \
19 "Trailer: Content-MD5\r\n" \
20 "\r\n"
22 end
24 digest = Digest::MD5.new
25 if buf = $stdin.readpartial(bs)
26 begin
27 digest.update(buf)
28 $stdout.write("%x\r\n" % [ buf.size ])
29 $stdout.write(buf)
30 $stdout.write("\r\n")
31 end while $stdin.read(bs, buf)
32 end
34 digest = [ digest.digest ].pack('m').strip
35 $stdout.write("0\r\n")
36 $stdout.write("Content-MD5: #{digest}\r\n\r\n")