2 # -*- encoding: binary -*-
3 # simple chunked HTTP PUT request generator (and just that),
4 # it reads stdin and writes to stdout so socat can write to a
5 # UNIX or TCP socket (or to another filter or file) along with
6 # a Content-MD5 trailer.
8 $stdout.sync
= $stderr.sync
= true
12 bs
= ENV['bs'] ? ENV['bs'].to_i
: 4096
14 if ARGV.grep("--no-headers").empty
?
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" \
24 digest
= Digest
::MD5.new
25 if buf
= $stdin.readpartial(bs
)
28 $stdout.write("%x\r\n" % [ buf
.size
])
31 end while $stdin.read(bs
, buf
)
34 digest
= [ digest
.digest
].pack('m').strip
35 $stdout.write("0\r\n")
36 $stdout.write("Content-MD5: #{digest}\r\n\r\n")