Transfer-Encoding: chunked in requests

"Dorian Taylor (Lists)" <[email protected]>
Newsgroups gmane.comp.apache.mod-perl
Message-ID <[email protected]>
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.