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