Content_Length in Dynamic File Upload using HTTP::Request::Common
Paul Salazar (ra1076@email.sps.mot.com)
Wed, 03 Feb 1999 08:00:04 -0600
My original mod forgot to reset $DYNAMIC_UPLOAD_LENGTH to 0,
resulting in bad behavior when doing multiple requests.
I am reposting original with fix.
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 (/dev/audio) are used in the filehandle.
I have hardcoded a value when doing the check on the
file mode (this should be changed).
*** Common.pm Tue Feb 2 13:02:50 1999
--- Common.pm.orig Tue Jan 19 10:05:27 1999
***************
*** 3,9 ****
package HTTP::Request::Common;
use strict;
! use vars qw(@EXPORT @EXPORT_OK $VERSION $DYNAMIC_FILE_UPLOAD
$DYNAMIC_UPLO
AD_LENGTH);
$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_FILE_UPLOAD ||= 0; # make it defined (don't know why)
***************
*** 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;
--- 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;
***************
*** 208,233 ****
"$CRLF--$boundary--$CRLF";
}
- # Modification to calculate content length of dynamic file
- # upload.
- my($chunk, @filestat);
- # Very important to zero out length before calc new length.
- $DYNAMIC_UPLOAD_LENGTH = 0;
- 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;
}
--- 203,208 ----
--
<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
# Paul R. Salazar Motorola - SPS/ATT #
# 3501 Ed Bluestein Blvd. sal@czar.sps.mot.com #
# Austin, TX 78721 MD:F15 Ph: (512) 933-3927 #
<<<<<<<<<<<<<<<<<<<<<<<<<<<<>>>>>>>>>>>>>>>>>>>>>>>>>>>>