CRLF bug (and fix) for HTTP/Request/Common.pm in libwww-perl-5.10

Kartik Subbarao (subbarao@aurora.lf.hp.com)
Fri, 11 Jul 1997 18:24:50 -0400


Kudos to Gisle and all the contributors to libwww-perl! It's a great package.

I found a small bug in HTTP/Request/Common.pm where HTTP output is 
line-terminated with just "\n", instead of "\r\n". It caused some problems
with a web server that I was working with. 

I saw that HTTP/Daemon.pm defines a CRLF variable and appends it to print 
statements. Using the same approach, I modified Common.pm. Attached below is a 
patch with the context diffs. I think I caught all the spots where it should 
be modified, but there could be other places that I might have missed.

	-Kartik

--
Kartik Subbarao, Internet Solution Center, Hewlett-Packard
Email: Kartik_Subbarao@hp.com, Phone: (302) 633-8830, Fax: (302) 633-7490
Inside HP:       http://aurora.lf.hp.com/home/
Internet Mirror: http://www.geocities.com/SiliconValley/Way/1234

--------------------------------------------------------------------------------
*** Common.pm.old	Sat May 24 15:08:33 1997
--- Common.pm	Fri Jul 11 17:48:24 1997
***************
*** 16,21 ****
--- 16,23 ----
  
  $VERSION = sprintf("%d.%02d", q$Revision: 1.2 $ =~ /(\d+)\.(\d+)/);
  
+ my $CRLF = "\015\012";   # "\r\n" is not portable
+ 
  sub GET  { _simple_req('GET',  @_); }
  sub HEAD { _simple_req('HEAD', @_); }
  sub PUT  { _simple_req('PUT' , @_); }
***************
*** 119,129 ****
  		$content = $h->header("Content");
  		$h->remove_header("Content");
  	    }
! 	    push(@parts, "Content-Disposition: $disp\n" .
!                          $h->as_string .
!                          "\n$content");
  	} else {
! 	    push(@parts, qq(Content-Disposition: form-data; name="$k"\n\n$v));
  	}
      }
      return "" unless @parts;
--- 121,131 ----
  		$content = $h->header("Content");
  		$h->remove_header("Content");
  	    }
! 	    push(@parts, "Content-Disposition: $disp$CRLF" .
!                          $h->as_string($CRLF) .
!                          "$CRLF$content");
  	} else {
! 	    push(@parts, qq(Content-Disposition: form-data; name="$k"$CRLF$CRLF$v));
  	}
      }
      return "" unless @parts;
***************
*** 143,151 ****
  	last;
      }
  
!     my $content = "--$boundary\n" .
!                   join("\n--$boundary\n", @parts) .
!                   "\n--$boundary--\n";
      wantarray ? ($content, $boundary) : $content;
  }
  
--- 145,153 ----
  	last;
      }
  
!     my $content = "--$boundary$CRLF" .
!                   join("$CRLF--$boundary$CRLF", @parts) .
!                   "$CRLF--$boundary--$CRLF";
      wantarray ? ($content, $boundary) : $content;
  }