Gisle Aas writes:
 > I'm trying to go through my backlog of bug reports and patches
 > for LWP. Today I've been fixing HTML::Form issues, and I've
 > just uploaded libwww-perl-5.70 as snapshot of this
 > work-in-progress. I expect more releases to come out soon.
 >
 > The changes that made it to v5.70 where:
 >
 > File::Listing::apache by Slaven Rezic <[EMAIL PROTECTED]>
 >
 > HEAD requests now work properly for ftp: URLs. Patch by Ville
 > Skytt� <[EMAIL PROTECTED]>.

I was having trouble with failed HEAD requests that delegated down to
Protocol/ftp.pm.  In my particular application I know that I have the
first START bytes, I just don't know how long the rest of the file is,
so I was calling HEAD so I could add a header to the request like
this:

  $request->header( Range => "bytes=$START-$END" );

However, after poking around a bit I found a much better solution to
my problem.  As documented here, 

  http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.35

a valid range request need not include an ending byte number.  Thus I
could just say

  $request->header( Range => "bytes=$START-" );

and be done with it.

However, the code that handles the Range header in LWP/Protocol/ftp.pm
can't handle this case -- it insists that the starting and ending byte
numbers both be defined.

I've attached a patch that fixes this particular case.  The spec
defines some more variations on how the range header can be used, but
I don't know how many of them are workable or useful for ftp.

Thanks,

-Matthew

*** ftp.pm.orig Mon Jul 28 19:25:09 2003
--- ftp.pm      Tue Aug  5 14:37:33 2003
***************
*** 247,264 ****
                my $range_info = $request->header('Range');
  
                # Change bytes=2772992-6781209 to just 2772992
!               my ($start_byte,$end_byte) = $range_info =~ /.*=\s*(\d+)-(\d+)/;
  
!               if (!defined $start_byte || !defined $end_byte ||
!                 ($start_byte < 0) || ($start_byte > $end_byte) || ($end_byte < 0))
!               {
!                 return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
!                    'Incorrect syntax for Range request');
                }
  
!               $max_size = $end_byte-$start_byte;
  
!               $ftp->restart($start_byte);
        }
        elsif ($request->header('Range') && !$ftp->supported('REST'))
        {
--- 247,271 ----
                my $range_info = $request->header('Range');
  
                # Change bytes=2772992-6781209 to just 2772992
!               my ($start_byte,$end_byte) = $range_info =~ /.*=\s*(\d+)-(\d+)?/;
!               if ( defined $start_byte && !defined $end_byte ) {
  
!                 # open range -- only the start is specified
! 
!                 $ftp->restart( $start_byte );
!                 # don't define $max_size, we don't want to abort early
                }
+               elsif ( defined $start_byte && defined $end_byte &&
+                       $start_byte >= 0 && $end_byte >= $start_byte ) {
  
!                 $ftp->restart( $start_byte );
!                 $max_size = $end_byte - $start_byte;
!               }
!               else {
  
!                 return HTTP::Response->new(&HTTP::Status::RC_BAD_REQUEST,
!                    'Incorrect syntax for Range request');
!               }
        }
        elsif ($request->header('Range') && !$ftp->supported('REST'))
        {

Reply via email to