Harald Joerg <[EMAIL PROTECTED]> writes:

> Once more I'd like to suggest a patch for HTTP::Response.
> 
> When working with my homegrown responses I found that the base method
> fails fatally if the response doesn't have a request inside:
> 
>    Can't call method "uri" on an undefined value at
>    /usr/lib/perl5/site_perl/5.8.5/HTTP/Response.pm line 78.
> 
> I can work around this by defining a fake request for my responses,
> but I'd prefer if HTTP::Response::base would simply return undef if
> it finds neither a base-defining header nor an embedded request.

Seems fine.  I tweaked your patch into this one before I applied it.
Thanks!

Regards,
Gisle

Index: lib/HTTP/Response.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/HTTP/Response.pm,v
retrieving revision 1.50
retrieving revision 1.51
diff -u -p -r1.50 -r1.51
--- lib/HTTP/Response.pm        30 Nov 2004 12:00:22 -0000      1.50
+++ lib/HTTP/Response.pm        11 Dec 2004 14:30:00 -0000      1.51
@@ -75,9 +75,20 @@ sub base
     my $base = $self->header('Content-Base')     ||  # used to be HTTP/1.1
                $self->header('Content-Location') ||  # HTTP/1.1
                $self->header('Base');                # HTTP/1.0
-    return $HTTP::URI_CLASS->new_abs($base, $self->request->uri);
-    # So yes, if $base is undef, the return value is effectively
-    # just a copy of $self->request->uri.
+    if ($base && $base =~ /^$URI::scheme_re:/o) {
+       # already absolute
+       return $HTTP::URI_CLASS->new($base);
+    }
+
+    my $req = $self->request;
+    if ($req) {
+        # if $base is undef here, the return value is effectively
+        # just a copy of $self->request->uri.
+        return $HTTP::URI_CLASS->new_abs($base, $req->uri);
+    }
+
+    # can't find an absolute base
+    return undef;
 }
 
 
@@ -366,6 +377,9 @@ received some redirect responses first.
 
 =back
 
+If neither of these sources provide an absolute URI, undef is
+returned.
+
 When the LWP protocol modules produce the HTTP::Response object, then
 any base URI embedded in the document (step 1) will already have
 initialized the "Content-Base:" header. This means that this method

Reply via email to