Matt Christian <[EMAIL PROTECTED]> writes:

> I originally sent this patch about a year ago* but it never made it into
> libwww-perl and no one followed up or replied to my original message.

That sometimes happen.  Sorry about that and thanks for not giving
up!

This patch kills the Content-Length both for the request itself and
for the multipart/* parts.  I think only the later is what you really
want.

I think the better fix is to simply remove the content-length for the
parts.  There is probably nothing that really requires them, even
though they ought to be harmless.  I don't want really want to
introduce yet another ugly global.

The content-length headers for parts could potentially be useful for
applications that might abort reading bigger uploads than their policy
allow after just seeing the headers.  Without these headers they have
to receive read lots of data in order to discover that it is too much.
If no "real" browser sends such a header then probably no server app
look at the header either. Any other opinions on this?

Regards,
Gisle


> I am still using this patch and need to apply it to every new libwww-perl
> that comes out so I am sending the (updated) patch again...
> 
> * original header ------------------------------------------------------
> From: Matt Christian <[EMAIL PROTECTED]>
> Subject: Patch for libwww-perl-5.69 to support not sending Content-Length...
> To: [EMAIL PROTECTED]
> Date: Wed May  7 14:10:34 2003 -0500
> ------------------------------------------------------------------------
> 
> Hi,
> 
> Attached is a patch for libwww-perl, specifically the
> HTTP/Request/Common.pm module to support not sending the Content-Length
> header in the MIME chunk for file uploads.  This is accomplished through
> a new (exportable) variable "$NO_LENGTH_FILE_UPLOAD" and done to support
> certain old/broken web servers that can't handle the Content-Length header.
> 
> (Unified) Patch for HTTP/Request/Common.pm
> --- Common.pm.orig    Thu May 20 16:14:48 2004
> +++ Common.pm Thu May 20 16:19:37 2004
> @@ -3,14 +3,15 @@
>  package HTTP::Request::Common;
>  
>  use strict;
> -use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD);
> +use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD 
> $NO_LENGTH_FILE_UPLOAD);
>  
>  $DYNAMIC_FILE_UPLOAD ||= 0;  # make it defined (don't know why)
> +$NO_LENGTH_FILE_UPLOAD ||= 0;
>  
>  require Exporter;
>  *import = \&Exporter::import;
>  @EXPORT =qw(GET HEAD PUT POST);
> [EMAIL PROTECTED] = qw($DYNAMIC_FILE_UPLOAD);
> [EMAIL PROTECTED] = qw($DYNAMIC_FILE_UPLOAD $NO_LENGTH_FILE_UPLOAD);
>  
>  require HTTP::Request;
>  use Carp();
> @@ -87,12 +88,16 @@
>  
>      $req->header('Content-Type' => $ct);  # might be redundant
>      if (defined($content)) {
> -     $req->header('Content-Length' =>
> -                  length($content)) unless ref($content);
> +     unless ($NO_LENGTH_FILE_UPLOAD) {
> +       $req->header('Content-Length' =>
> +                    length($content)) unless ref($content);
> +        }
>       $req->content($content);
>      }
>      else {
> -        $req->header('Content-Length' => 0);
> +     unless ($NO_LENGTH_FILE_UPLOAD) {
> +          $req->header('Content-Length' => 0);
> +        }
>      }
>      $req;
>  }
> @@ -152,7 +157,10 @@
>                   local($/) = undef; # slurp files
>                   $content = <$fh>;
>                   close($fh);
> -                 $h->header("Content-Length" => length($content));
> +
> +                 unless ($NO_LENGTH_FILE_UPLOAD) {
> +                   $h->header("Content-Length" => length($content));
> +                 }
>               }
>               unless ($ct) {
>                   require LWP::MediaTypes;
> @@ -438,6 +446,12 @@
>  applications) like this.  Also, if the file(s) change in size between
>  the time the Content-Length is calculated and the time that the last
>  chunk is delivered, the subroutine will C<Croak>.
> +
> +Alternatively, if you set the $NO_LENGTH_FILE_UPLOAD variable
> +(exportable) to some TRUE value, then the Content-Length header will
> +NOT be set for the file upload MIME chunk.  This allow you to
> +upload files to old/broken web servers that cannot handle
> +Content-Length headers.
>  
>  =back
>  
> 

Reply via email to