Hi-

I've found a bug of sorts in the way LWP::Protocol::ftp handles HEAD
requests.  After it makes the initial request for data and jams the
number of bytes into the Content-Length header, it then tries to
properly close the data connection.  Unfortunately, at least for the
ftp server I was communicating with, the aborted data transfer (ABOR)
often results in an error deep within Net::Cmd.  This in turn kills
the useful HTTP::Response that had been built up, and replaces it with
a 500 (Internal Server Error) response.

My fix was to eval the $data->close() if the request was just for the
head, and then just happily return the $response that had been
generated, whether the $data->close() worked or otherwise.

I suspect this might have a bad interaction if there is a connection
cache is being used, but I'm not sure.  In any case, the patch is
attached.

-Matthew

*** ftp.pm.orig Fri Oct 26 13:13:20 2001
--- ftp.pm      Mon Jul 28 19:25:09 2003
***************
*** 280,285 ****
--- 280,292 ----
                $response->header('Content-Length', "$1");
            }
  
+           if ( $method eq 'HEAD' ) {
+             # the useful work is already done, so don't lose the response
+             # just because we might not shut down cleanly
+             eval { $data->close };
+             return $response;
+           }
+ 
            if ($method ne 'HEAD') {
                # Read data from server
                $response = $self->collect($arg, $response, sub {

Reply via email to