Reading http chunked body
Here is my implementation of Chunked Transfer Coding. I find it quite elegant compared to other snippets i’ve seen.
###################################################
# {{{ read body chunked
###################################################
sub getbodychunked
{
my $sh = shift; # the socket handle should be passed
my ($in, $body);
for ($in = < $sh>; defined $in; $in = < $sh>)
{
$in = trim $in;
my $chunk = hex $in;
while (defined $in && $chunk > 0)
{
$chunk -= read $sh, $in, $chunk;
$body .= $in;
}
}
return $body;
}