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