]> granicus.if.org Git - apache/blob - test/check_chunked
describe the recent changes to mod_headers (%%, envclause everywhere)
[apache] / test / check_chunked
1 #!/usr/bin/perl -w
2 #
3 # Copyright 2000-2004 The Apache Software Foundation
4 #
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
8 #
9 #     http://www.apache.org/licenses/LICENSE-2.0
10 #
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
16 #
17 #
18 # This is meant to be used on the raw output of an HTTP/1.1 connection
19 # to check that the chunks are all correctly laid out.  It's easiest
20 # to use a tool like netcat to generate the output.  This script
21 # *insists* that \r exist in the output.
22 #
23 # You can find netcat at avian.org:/src/hacks/nc110.tgz.
24
25 use strict;
26
27 my $is_chunked = 0;
28
29 # must toss headers
30 while(<>) {
31     if (/^Transfer-Encoding:\s+chunked/i) {
32         $is_chunked = 1;
33     }
34     last if ($_ eq "\r\n");
35 }
36
37 $is_chunked || die "wasn't chunked\n";
38
39 for(;;) {
40     $_ = <> || die "unexpected end of file!\n";
41
42     m#^([0-9a-f]+) *\r$#i || die "bogus chunklen: $_";
43
44     my $chunklen = hex($1);
45
46     exit 0 if ($chunklen == 0);
47
48     chop; chop;
49     print "$_ ";
50
51     my $data = '';
52     read(ARGV, $data, $chunklen) == $chunklen || die "short read!\n";
53
54     $_ = <> || die "unexpected end of file!\n";
55
56     $_ eq "\r\n" || die "missing chunk trailer!\n";
57 }