WWW::HTTP

Andreas Koenig (andreas@filomena.techne.co.uk)
Tue, 14 Mar 1995 14:28:55 +0000 (BST)


Yesterday I started investigating Martijn's work on the modules and
found a bug in HTTP.pm. The forth chunk of my patch below fixes it ($2
is emptry after the regexes that uppercase $lastkey).

The other three chunks are a matter of style. I'd prefer to have
modules that don't die except in very, very weird situations. I
realize, that you're solving your dies by evaling a lot, but isn't
that a high prize?

I have also a question regarding objecthood. Currently URL.pm doesn't
bless an object. I'm constantly parsing and composing with code like
so:

    @unified{SCHEME,ADDRESS,PORT,PATH,QUERY,FRAG}=WWW::URL::parse($_);

Is the objectification of the URL in the works, or are you intending
to leave the package as is?

Unfortunately I don't have access to my mail archive, so I cannot read
your recent message about the URL class. Could you help me getting the
picture once again, please? THANKS!

andreas

--- HTTP.pm.MK	Tue Mar 14 08:10:52 1995
+++ HTTP.pm	Tue Mar 14 11:36:52 1995
@@ -276,7 +276,7 @@
     $SIG{'ALRM'} = undef;
     
     if (defined $@ and $@) {
-	croak $@;
+	confess $@;
     }
     else {
 	return $response;
@@ -311,8 +311,10 @@
 
     $port = &getport($port);
     my $that = &getaddress($hostname, $port);
-    connect($SocketHandle, $that) || die 
-	"connect to host '$hostname' on port '$port': $!";
+    unless (connect($SocketHandle, $that)){
+	confess "connect to host '$hostname' on port '$port': $!";
+	return;
+    }
 
     &debug("Connected to host '$hostname' on port '$port'\n");
 
@@ -344,7 +346,10 @@
     $_ = <$SocketHandle>;
     $WWW::HTTP::SocketHandle->input_record_separator($irs);
 
-    croak "No response.\n" unless defined $_;
+    unless (defined $_){
+	confess "No response.\n";
+	return;
+    }
 
     # parse response header
     
@@ -379,10 +384,10 @@
 		push(@{$self->{'Header'}{$lastkey}}, $lastval) if
 		    (defined $lastkey and defined $lastval);
 		$lastkey = $1;
+		$lastval = $2;
 		# capitalise words e.g. user-agent -> User-Agent
 		$lastkey =~ s/^(.)/\U$1/;
 	        $lastkey =~ s/-(.)/-\U$1/g;
-		$lastval = $2;
 	    }
 	    elsif(/\s+(.*)/) {
 		croak "Unexpected header continuation" unless 



END_OF_PATCH