]> granicus.if.org Git - apache/blob - test/check_chunked
Apache 1.3.9 baseline for the Apache 2.0 repository.
[apache] / test / check_chunked
1 #!/usr/bin/perl -w
2
3 # This is meant to be used on the raw output of an HTTP/1.1 connection
4 # to check that the chunks are all correctly laid out.  It's easiest
5 # to use a tool like netcat to generate the output.  This script
6 # *insists* that \r exist in the output.
7 #
8 # You can find netcat at avian.org:/src/hacks/nc110.tgz.
9
10 use strict;
11
12 my $is_chunked = 0;
13
14 # must toss headers
15 while(<>) {
16     if (/^Transfer-Encoding:\s+chunked/i) {
17         $is_chunked = 1;
18     }
19     last if ($_ eq "\r\n");
20 }
21
22 $is_chunked || die "wasn't chunked\n";
23
24 for(;;) {
25     $_ = <> || die "unexpected end of file!\n";
26
27     m#^([0-9a-f]+) *\r$#i || die "bogus chunklen: $_";
28
29     my $chunklen = hex($1);
30
31     exit 0 if ($chunklen == 0);
32
33     chop; chop;
34     print "$_ ";
35
36     my $data = '';
37     read(ARGV, $data, $chunklen) == $chunklen || die "short read!\n";
38
39     $_ = <> || die "unexpected end of file!\n";
40
41     $_ eq "\r\n" || die "missing chunk trailer!\n";
42 }