check_chunked revision 09fe0b69d3d1e8c8041c9ce99ee77b8b44b5e3b1
563N/A#!/usr/bin/perl -w
563N/A
563N/A# This is meant to be used on the raw output of an HTTP/1.1 connection
563N/A# to check that the chunks are all correctly laid out. It's easiest
563N/A# to use a tool like netcat to generate the output. This script
563N/A# *insists* that \r exist in the output.
563N/A#
563N/A# You can find netcat at avian.org:/src/hacks/nc110.tgz.
563N/A
563N/Ause strict;
563N/A
563N/Amy $is_chunked = 0;
563N/A
563N/A# must toss headers
563N/Awhile(<>) {
563N/A if (/^Transfer-Encoding:\s+chunked/i) {
563N/A $is_chunked = 1;
563N/A }
873N/A last if ($_ eq "\r\n");
563N/A}
563N/A
563N/A$is_chunked || die "wasn't chunked\n";
563N/A
563N/Afor(;;) {
733N/A $_ = <> || die "unexpected end of file!\n";
563N/A
563N/A m#^([0-9a-f]+) *\r$#i || die "bogus chunklen: $_";
563N/A
563N/A my $chunklen = hex($1);
563N/A
563N/A exit 0 if ($chunklen == 0);
563N/A
563N/A chop; chop;
563N/A print "$_ ";
563N/A
563N/A my $data = '';
563N/A read(ARGV, $data, $chunklen) == $chunklen || die "short read!\n";
563N/A
563N/A $_ = <> || die "unexpected end of file!\n";
563N/A
1509N/A $_ eq "\r\n" || die "missing chunk trailer!\n";
1073N/A}
1323N/A