[Testcase][Patch] http protocol

Rocco Caputo (troc@netrus.net)
Fri, 08 Jan 99 09:02:00 -0500


Greetings.  This patch changes two things in LWP/Protocol/http.pm.

1. At least one system still reads POST data by lines instead of by
Content-Length.  This leads to "it works in the browser but doesn't in
LWP" behavior.  The patch appends an "invisible" $CRLF (not accounted
for in Content-Length) to content if a trailing $CRLF isn't present.

2. The "+conns" debug level displays the request's headers twice,
instead of displaying the headers and contents.  The patch fixes this.

Test program:

#!/usr/bin/perl -w
use strict;

use HTTP::Request::Common qw(GET POST);
use LWP::UserAgent;
use LWP::Debug qw(level);

level('+debug');
level('+trace');
level('+conns');

my $ua = new LWP::UserAgent;
$ua->env_proxy;

my $word = 'door';
my $request =
  POST 'http://www.link.cs.cmu.edu/cgi-bin/dougb/rhyme.cgi',
  [ 'word'        => $word,
    'typeofrhyme' => 'perfect',
  ];

print $request->as_string(), "\n\n";

my $return;

if (my $response = $ua->request($request)) {
  my ($text) = $response->content;
  $text =~ s/\s+/ /g;
  print $text;
}
else {
  print "Request failed.\n";
}
__END__

Patch:

--- http.pm.orig	Thu Nov 19 16:45:00 1998
+++ http.pm	Fri Jan  8 08:54:08 1999
@@ -137,11 +137,12 @@ sub request
 	    LWP::Debug::conns($buf);
 	}
     } elsif (defined($$cont_ref) && length($$cont_ref)) {
+	$$cont_ref =~ s/($CRLF)?$/$CRLF/o;
 	die "write timeout" if $timeout && !$sel->can_write($timeout);
 	$n = $socket->syswrite($$cont_ref, length($$cont_ref));
 	die $! unless defined($n);
 	die "short write" unless $n == length($$cont_ref);
-	LWP::Debug::conns($buf);
+	LWP::Debug::conns($$cont_ref);
     }
     
     # read response line from server
__END__

-- Rocco Caputo / troc@netrus.net