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.
Patches for lib/HTTP/Response.pm and t/base/message-old.t attached. -- Cheers, haj
--- lib/HTTP/Response.pm.1.50 2004-12-02 21:36:42.437500000 +0100 +++ lib/HTTP/Response.pm 2004-12-06 23:11:47.000000000 +0100 @@ -76,7 +82,13 @@ $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 ($self->request) { + 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. + } else { + return $base; + # If, on the other hand, $self->request is undef, the return + # value is $base as found in the headers. + } } @@ -367,4 +379,6 @@ =back +If neither of these sources provide a 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
--- t/base/message-old.t~ 2004-04-09 10:50:21.000000000 +0200 +++ t/base/message-old.t 2004-12-06 22:53:21.663750000 +0100 @@ -8,5 +8,5 @@ use Test qw(plan ok); -plan tests => 19; +plan tests => 20; require HTTP::Request; @@ -63,4 +63,5 @@ # Check the base method: $res = HTTP::Response->new(200, "This message"); +ok($res->base, undef); $res->request($req); $res->content_type("image/gif");