LWP::Simple bug

Richard Chen (richard@lexitech.com)
Wed, 03 Feb 1999 10:31:52 -0500


There is a subtle bug in the head subroutine
of the LWP::Simple module. The problem is that
it does not always return a 5 element list
even if it is successful, contrary to the man page.

For example, the 4th element of the list should
show the Server software:

$ perl -MLWP::Simple -e 'print +(head("http://www.perl.org/"))[4],"\n"'
Apache/1.3.4 (Unix) Debian/GNU

But this is not guaranteed to work:
$ perl -MLWP::Simple -e 'print
+(head("http://www.slashdot.org/"))[4],"\n"'

The source of the problem is the treatment of
array/scalar context. The fix is contained in the
following patch file:


$ cat Simple.patch 
*** Simple.pm.orig      Wed Feb  3 10:12:19 1999
--- Simple.pm   Wed Feb  3 10:12:42 1999
***************
*** 218,228 ****
  
      if ($response->is_success) {
        return $response unless wantarray;
!       return ($response->header('Content-Type'),
!               $response->header('Content-Length'),
!              
HTTP::Date::str2time($response->header('Last-Modified')),
!               HTTP::Date::str2time($response->header('Expires')),
!               $response->header('Server'),
               );
      }
      return;
--- 218,228 ----
  
      if ($response->is_success) {
        return $response unless wantarray;
!       return (scalar $response->header('Content-Type'),
!               scalar $response->header('Content-Length'),
!               scalar
HTTP::Date::str2time($response->header('Last-Modified')),
!               scalar
HTTP::Date::str2time($response->header('Expires')),
!               scalar $response->header('Server'),
               );
      }
      return;

-- 
Richard Chen
Lexitech Multimedia
203-483-2895 ext 232
richard@lexitech.com