3 # Copyright 2000-2004 The Apache Software Foundation
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
9 # http://www.apache.org/licenses/LICENSE-2.0
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.
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.
23 # You can find netcat at avian.org:/src/hacks/nc110.tgz.
31 if (/^Transfer-Encoding:\s+chunked/i) {
34 last if ($_ eq "\r\n");
37 $is_chunked || die "wasn't chunked\n";
40 $_ = <> || die "unexpected end of file!\n";
42 m#^([0-9a-f]+) *\r$#i || die "bogus chunklen: $_";
44 my $chunklen = hex($1);
46 exit 0 if ($chunklen == 0);
52 read(ARGV, $data, $chunklen) == $chunklen || die "short read!\n";
54 $_ = <> || die "unexpected end of file!\n";
56 $_ eq "\r\n" || die "missing chunk trailer!\n";