perl-modperl mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Dorian Taylor (Lists)" <dorian.taylor.li...@gmail.com>
Subject Transfer-Encoding: chunked in requests
Date Mon, 04 Oct 2010 16:29:45 GMT
Hi all,

Is there a best-practice solution for dealing with requests with  
chunked transfer encoding? About the only thing I could do to get it  
to cooperate was this:

     # pull headers
     my $hdr = HTTP::Headers->new;
     map { $hdr->header($_, $r->headers_in->get($_)) } keys %{$r- 
 >headers_in};

     my ($buf, $cl) = ('', $hdr->header('Content-Length'));
     if (defined $cl and $cl =~ /^\d+$/ and $cl > 0) {
         $r->read($buf, $cl);
     }
     elsif (($hdr->header('Transfer-Encoding') || '') =~ /chunked/i) {
         # AHA. chunked.
         $r->setup_client_block(2); # REQUEST_CHUNKED_DECHUNK
         my $chunk = '';
         while (my $n = $r->get_client_block($chunk, 2048)) {
             # warn $n;
             $buf .= $chunk;
         }
         $hdr->header('Content-Length', length $buf);
         $hdr->remove_header('Transfer-Encoding');
     }
     else {
         $r->discard_request_body;
     }

$r->read() seems to have no effect when the input is chunked but the  
docs warn against using $r->get_client_block. I did notice that  
get_client_block clobbers $chunk instead of appending to it  
(originally I had it as $buf). So I'm interested if there is a more  
appropriate way to do this.

For reference, I am using: Apache/2.2.11 (Ubuntu) DAV/2 SVN/1.5.4  
mod_perl/2.0.4 Perl/v5.10.0

Thanks,

--
Dorian Taylor
Make things. Make sense.
http://doriantaylor.com


Mime
View raw message