Blame test/check_chunked

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