check_chunked revision a2652f3451528565db1f85db6953fc30799d7ead
1281N/A#!/usr/bin/perl -w
1186N/A#
1186N/A# Copyright 2000-2006 The Apache Software Foundation or its licensors, as
0N/A# applicable.
0N/A#
0N/A# Licensed under the Apache License, Version 2.0 (the "License");
1281N/A# you may not use this file except in compliance with the License.
0N/A# You may obtain a copy of the License at
0N/A#
0N/A# http://www.apache.org/licenses/LICENSE-2.0
0N/A#
0N/A# Unless required by applicable law or agreed to in writing, software
0N/A# distributed under the License is distributed on an "AS IS" BASIS,
0N/A# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0N/A# See the License for the specific language governing permissions and
0N/A# limitations under the License.
0N/A#
0N/A#
0N/A# This is meant to be used on the raw output of an HTTP/1.1 connection
0N/A# to check that the chunks are all correctly laid out. It's easiest
1297N/A# to use a tool like netcat to generate the output. This script
0N/A# *insists* that \r exist in the output.
1186N/A#
1186N/A# You can find netcat at avian.org:/src/hacks/nc110.tgz.
1186N/A
1186N/Ause strict;
1186N/A
1186N/Amy $is_chunked = 0;
1186N/A
1186N/A# must toss headers
0N/Awhile(<>) {
1186N/A if (/^Transfer-Encoding:\s+chunked/i) {
1186N/A $is_chunked = 1;
1186N/A }
1186N/A last if ($_ eq "\r\n");
1186N/A}
1186N/A
1186N/A$is_chunked || die "wasn't chunked\n";
962N/A
1186N/Afor(;;) {
1186N/A $_ = <> || die "unexpected end of file!\n";
1281N/A
1281N/A m#^([0-9a-f]+) *\r$#i || die "bogus chunklen: $_";
1281N/A
1281N/A my $chunklen = hex($1);
1281N/A
1281N/A exit 0 if ($chunklen == 0);
1281N/A
962N/A chop; chop;
1281N/A print "$_ ";
1281N/A
1281N/A my $data = '';
1281N/A read(ARGV, $data, $chunklen) == $chunklen || die "short read!\n";
1281N/A
1281N/A $_ = <> || die "unexpected end of file!\n";
1281N/A
1281N/A $_ eq "\r\n" || die "missing chunk trailer!\n";
1281N/A}
1281N/A