HTTP::Request::Common mod

Paul Salazar (ra1076@email.sps.mot.com)
Tue, 19 Jan 1999 14:48:03 -0600


This is a multi-part message in MIME format.
--------------12CD3764B399C61877DB0215
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

This is for Gisle Aas,

I had a need to use POST method using $DYNAMIC_FILE_UPLOAD variable
set. The problem I had was that the Content-Length would not
be set, so I have coded up a modification to calculation
the Content-Length using $DYNAMIC_FILE_UPLOAD set. The
modification only works with real files and uses the old
behavior if any devices are used in the filehandle. I
have hardcoded a value when doing the check on the
file mode (this should be changed).

I have attached a diff file.


Regards,
-- Paul

<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#  Paul R. Salazar                Motorola - SPS/ATT   #
#  3501 Ed Bluestein Blvd.        sal@czar.sps.mot.com #
#  Austin, TX 78721  MD:F15       Ph: (512) 933-3927   #
<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>
--------------12CD3764B399C61877DB0215
Content-Type: text/plain; charset=us-ascii; name="Common.pm.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline; filename="Common.pm.diff"

*** Common.pm	Tue Jan 19 14:33:49 1999
--- Common.pm.new	Tue Jan 19 14:33:49 1999
***************
*** 3,9 ****
  package HTTP::Request::Common;
  
  use strict;
! use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD);
  
  $DYNAMIC_FILE_UPLOAD ||= 0;  # make it defined (don't know why)
  
--- 3,9 ----
  package HTTP::Request::Common;
  
  use strict;
! use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD $DYNAMIC_UPLOAD_LENGTH);
  
  $DYNAMIC_FILE_UPLOAD ||= 0;  # make it defined (don't know why)
  
***************
*** 62,69 ****
  
      $req->header('Content-Type' => $ct);  # might be redundant
      if (defined($content)) {
! 	$req->header('Content-Length' =>
! 		     length($content)) unless ref($content);
  	$req->content($content);
      }
      $req;
--- 62,74 ----
  
      $req->header('Content-Type' => $ct);  # might be redundant
      if (defined($content)) {
!        if (ref($content)){
! 	  $req->header('Content-Length' =>
! 		       $DYNAMIC_UPLOAD_LENGTH ) if $DYNAMIC_UPLOAD_LENGTH;
!        }
!        else {
! 	  $req->header('Content-Length' => length($content));
!        }
  	$req->content($content);
      }
      $req;
***************
*** 203,208 ****
--- 208,231 ----
  		   "$CRLF--$boundary--$CRLF";
      }
  
+     # Modification to calculate content length of dynamic file
+     # upload.
+     my($chunk, @filestat);
+ FILE: foreach $chunk (@parts){
+         if(ref $chunk){
+ 	   $DYNAMIC_UPLOAD_LENGTH += length $$chunk[0];
+ 	   @filestat = stat $$chunk[1];
+ 	   $DYNAMIC_UPLOAD_LENGTH += $filestat[7];
+ 	   # Make sure its a real file.
+ 	   unless($filestat[2] & 32768){
+ 	      $DYNAMIC_UPLOAD_LENGTH = 0;
+ 	      last FILE;
+ 	   }
+ 	}
+ 	else {
+ 	   $DYNAMIC_UPLOAD_LENGTH += length $chunk;
+ 	}
+      }
      wantarray ? ($content, $boundary) : $content;
  }
  

--------------12CD3764B399C61877DB0215--