Re: LWP::UserAgent -- Bug in $response->message
Gisle Aas (gisle@activestate.com)
14 Mar 2001 12:45:17 -0800
Bjoern Hoehrmann <derhoermi@gmx.net> writes:
> * Boris 'pi' Piwinger wrote:
> >After some discussion in de.comp.lang.perl.misc
> >(<3AA7785F.62A4C7B4@logic.univie.ac.at> ff) I assume there is a bug in
> >LWP::UserAgent. I have a while loop reading URLs from a file. Those
> >are fetched, if unsuccessful the response code and message are
> >printed. The message becomes, e.g.:
> >
> >Can't connect to www.polybytes.com:80 (No route to host), <FILE> chunk
> >1.
> >
> >Obviously everything from the comma on is not correct at this place.
> >Someone suggested that in LWP::Protocol::http::_new_socket the message
> >does not end in \n.
>
> Yes, that was me. die() is used there and `perldoc -f die` reads
>
> | If the value of EXPR does not end in a newline, the current
> | script line number and input line number (if any) are also
> | printed, and a newline is supplied. Note that the "input line
> | number" (also known as "chunk") is subject to whatever notion of
> | "line" happens to be currently in effect, and is also available
> | as the special variable `$.'. See the section on "$/" in the
> | perlvar manpage and the section on "$." in the perlvar manpage.
>
> In LWP::UserAgent this is caught:
>
> | if ($use_eval) {
> | # we eval, and turn dies into responses below
> | eval {
> | $response = $protocol->request($request, $proxy,
> | $arg, $size, $timeout);
> | };
> | if ($@) {
> | $@ =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*//;
> | $response =
> | HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
> | $@);
> | }
>
> The regular expression should be extended to remove also
>
> /,\s+<HANDLE>\s+(?:line|chunk)\s+\d+\.?\s*/
I think I'll just simplify it a bit:
Index: lib/LWP/UserAgent.pm
===================================================================
RCS file: /cvsroot/libwww-perl/lwp5/lib/LWP/UserAgent.pm,v
retrieving revision 1.76
diff -u -p -u -r1.76 UserAgent.pm
--- lib/LWP/UserAgent.pm 2001/03/14 20:22:28 1.76
+++ lib/LWP/UserAgent.pm 2001/03/14 20:44:10
@@ -185,7 +185,7 @@ sub simple_request
$protocol = LWP::Protocol::create($scheme);
};
if ($@) {
- $@ =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*//; # remove file/line number
+ $@ =~ s/\s+at\s+\S+\s+line\s+\d+.*//; # remove file/line number
return HTTP::Response->new(&HTTP::Status::RC_NOT_IMPLEMENTED, $@)
}
@@ -213,7 +213,7 @@ sub simple_request
$arg, $size, $timeout);
};
if ($@) {
- $@ =~ s/\s+at\s+\S+\s+line\s+\d+\.?\s*//;
+ $@ =~ s/\s+at\s+\S+\s+line\s+\d+.*//;
$response =
HTTP::Response->new(&HTTP::Status::RC_INTERNAL_SERVER_ERROR,
$@);
Regards,
Gisle