stas        2004/07/01 14:19:19

  Modified:    .        Changes
               t/api    sendfile.t
               t/response/TestAPI sendfile.pm
               xs/Apache/RequestIO Apache__RequestIO.h
  Log:
  - fix a bug when offset is passed, but not len
  - add tests for offset and offset+len
  - restructure the test
  
  Revision  Changes    Path
  1.396     +1 -1      modperl-2.0/Changes
  
  Index: Changes
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/Changes,v
  retrieving revision 1.395
  retrieving revision 1.396
  diff -u -u -r1.395 -r1.396
  --- Changes   1 Jul 2004 20:25:25 -0000       1.395
  +++ Changes   1 Jul 2004 21:19:18 -0000       1.396
  @@ -21,7 +21,7 @@
   
   APR::RequestIO::sendfile() now flushes any buffered output before
   sending the file contents out. If the return status is not checked and
  -an error happens it'll throw an exception. [Stas]
  +an error happens it'll throw an exception. Fix offset handling. [Stas]
   
   Registry: remove the misleading prefix "$$: $class:" in the logged
   error message, since not only registry errors will get logged if $@ is
  
  
  
  1.10      +29 -26    modperl-2.0/t/api/sendfile.t
  
  Index: sendfile.t
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/api/sendfile.t,v
  retrieving revision 1.9
  retrieving revision 1.10
  diff -u -u -r1.9 -r1.10
  --- sendfile.t        1 Jul 2004 20:25:25 -0000       1.9
  +++ sendfile.t        1 Jul 2004 21:19:19 -0000       1.10
  @@ -12,49 +12,52 @@
   my $file = catfile Apache::Test::vars('serverroot'),
       'response/TestAPI/sendfile.pm';
   
  +my $contents;
  +open my $fh, $file or die "can't open $file: $!";
  +# need binmode on Win32 so as not to strip \r, which
  +# are included when sending with sendfile().
  +binmode $fh;
  +{ local $/; $contents = <$fh>; }
  +close $fh;
  +
   plan tests => 7;
   
   {
       my $header = "This is a header\n";
       my $footer = "This is a footer\n";
   
  -    open my $fh, $file or die "can't open $file: $!";
  -    local $/;
  -    # need binmode on Win32 so as not to strip \r, which
  -    # are included when sending with sendfile().
  -    binmode $fh;
  -    my $expected = join '', $header, <$fh>, $footer;
  -    close $fh;
  +    my $received = GET_BODY "$url?withwrapper";
  +    my $expected = join '', $header, $contents, $footer;
  +    #t_debug($received);
  +    ok $received && $received eq $expected;
  +}
   
  -    my $received = GET_BODY($url);
  +{
  +    my $received = GET_BODY "$url?offset";
  +    my $expected = substr $contents, 3;
  +    #t_debug($received);
  +    ok $received && $received eq $expected;
  +}
   
  -    t_debug($received);
  +{
  +    my $received = GET_BODY "$url?len";
  +    my $expected = substr $contents, 3, 50;
  +    #t_debug($received);
       ok $received && $received eq $expected;
   }
   
   {
  +    # rc is checked and handled by the code
       my $res = GET "$url?noexist.txt";
  -    # 200 even though it wasn't found (since an output was sent before
  -    # sendfile was done)
  -    ok t_cmp($res->code, 200, "output already sent");
  -    t_debug($res->content);
  +    ok t_cmp($res->code, 500, "failed sendfile");
  +    #t_debug($res->content);
       ok $res->content =~ /an internal error/;
   }
   
   {
  +    # rc is not checked in this one, testing the exception throwing
       my $res = GET "$url?noexist-n-nocheck.txt";
  -    # 200 even though it wasn't found (since an output was sent before
  -    # sendfile was done)
  -    ok t_cmp($res->code, 200, "output already sent");
  -    t_debug($res->content);
  +    ok t_cmp($res->code, 500, "failed sendfile");
  +    #t_debug($res->content);
       ok $res->content =~ /an internal error/;
  -}
  -
  -{
  -    # this time no printed output but the attempt to read a
  -    # non-existing file
  -    my $res = GET "$url?noexist-n-noheader.txt";
  -    ok t_cmp($res->code, 404, "");
  -    t_debug($res->content);
  -    ok $res->content =~ /$url was not found/;
   }
  
  
  
  1.5       +22 -17    modperl-2.0/t/response/TestAPI/sendfile.pm
  
  Index: sendfile.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/t/response/TestAPI/sendfile.pm,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -u -r1.4 -r1.5
  --- sendfile.pm       1 Jul 2004 20:25:25 -0000       1.4
  +++ sendfile.pm       1 Jul 2004 21:19:19 -0000       1.5
  @@ -13,29 +13,34 @@
       my $r = shift;
   
       $r->content_type('text/plain');
  -    my $file = $r->args || __FILE__;
  +    my $args = $r->args;
   
  -    # buffer output up, so we can test that sendfile flushes any
  -    # buffered output before sending the file contents out
  -    local $|;
  -    $r->print("This is a header\n")
  -        unless $file eq 'noexist-n-noheader.txt';
  -
  -    if ($file eq 'noexist-n-nocheck.txt') {
  -        eval { $r->sendfile($file) };
  +    if ($args eq 'withwrapper') {
  +        # buffer output up, so we can test that sendfile flushes any
  +        # buffered output before sending the file contents out
  +        local $|;
  +        $r->print("This is a header\n");
  +        $r->sendfile(__FILE__);
  +        $r->print("This is a footer\n");
  +    }
  +    elsif ($args eq 'offset') {
  +        $r->sendfile(__FILE__, 3);
  +    }
  +    elsif ($args eq 'len') {
  +        $r->sendfile(__FILE__, 3, 50);
  +    }
  +    elsif ($args eq 'noexist-n-nocheck.txt') {
  +        eval { $r->sendfile($args) };
           return int $@;
       }
       else {
  -        my $rc = $r->sendfile($file);
  -        unless ($rc == APR::SUCCESS) {
  -            # warn APR::Error::strerror($rc);
  -            return $file eq 'noexist-n-noheader.txt'
  -                ? Apache::NOT_FOUND
  -                : $rc;
  -        }
  +        my $rc = $r->sendfile($args);
  +        # warn APR::Error::strerror($rc);
  +        return $rc unless $rc == APR::SUCCESS;
       }
   
  -    $r->print("This is a footer\n");
  +    # XXX: can't quite test bogus offset and/or len, since ap_send_fd
  +    # doesn't provide any error indications
   
       return Apache::OK;
   }
  
  
  
  1.50      +3 -0      modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h
  
  Index: Apache__RequestIO.h
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/xs/Apache/RequestIO/Apache__RequestIO.h,v
  retrieving revision 1.49
  retrieving revision 1.50
  diff -u -u -r1.49 -r1.50
  --- Apache__RequestIO.h       1 Jul 2004 20:25:25 -0000       1.49
  +++ Apache__RequestIO.h       1 Jul 2004 21:19:19 -0000       1.50
  @@ -333,6 +333,9 @@
           apr_finfo_t finfo;
           apr_file_info_get(&finfo, APR_FINFO_NORM, fp);
           len = finfo.size;
  +        if (offset) {
  +            len -= offset;
  +        }
       }
   
       /* flush any buffered modperl output */
  
  
  

Reply via email to