Rodrigo Ruiz <[EMAIL PROTECTED]> writes:

> I need to perform a PUT operation and send a very large file (several
> hundred MBytes). I have been using the following code to do this:
> 
>     ...
>     my $header = HTTP::Headers->new;
>     $header->content_type('application/octet-stream');
>     $header->content_length($fileSize);
>     $header->authorization_basic($usr, $pwd);
> 
>     my $readFunc = sub {
>       read(FH, my $buf, 65536);
>       return $buf;
>     };
> 
>     my $req = HTTP::Request->new("PUT", $url, $header, $readFunc);
>     ...

Seems sane.

> But after updating to the 5.802 version of LWP this code has stopped
> working.
> 
> When I execute my script, it prints a warning telling me that the
> Content-Length header has been fixed, and the file in the destination
> server is corrupted.
> Looking at the code of the library, I have found these lines:
> 
> # Set (or override) Content-Length header
> my $clen = $request_headers->header('Content-Length');
> if (defined($$content_ref) && length($$content_ref)) {
>  $has_content++;
>  if (!defined($clen) || $clen ne length($$content_ref)) {
>    if (defined $clen) {
>      warn "Content-Length header value was wrong, fixed";
>      hlist_remove([EMAIL PROTECTED], 'Content-Length');
>    }
>    push(@h, 'Content-Length' => length($$content_ref));
>  }
> } elsif ($clen) {
>  warn "Content-Length set when there is not content, fixed";
>  hlist_remove([EMAIL PROTECTED], 'Content-Length');
> }
> 
> I think these lines prevent the use of a function as the content reference.
> 
> Is this a bug, or the support for function references has been removed?

No this is supposed to work.  This code block should not be entered as
there is a test for code reference content just above it.  Can you
figure out why the:

  if (ref($content_ref) eq 'CODE') {

test fails?  What is $content_ref in this case?

Regards,
Gisle

Reply via email to