stas        2003/08/06 00:30:31

  Added:       ModPerl-Registry/t 304.t
               ModPerl-Registry/t/cgi-bin 304.pl
  Log:
  304 registry tests
  
  Revision  Changes    Path
  1.1                  modperl-2.0/ModPerl-Registry/t/304.t
  
  Index: 304.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest qw(GET);
  
  plan tests => 4;
  
  my $url = "/registry/304.pl";
  
  {
      # not modified
      my $if_modified_since = 'Sun, 29 Oct 2000 15:55:00 GMT';
      my $res = GET($url, 'If-Modified-Since' => $if_modified_since);
  
      ok t_cmp(
          304,
          $res->code,
          "test HTTP_NOT_MODIFIED (304 status)",
      );
  
      ok t_cmp(
          '',
          $res->content,
          "test HTTP_NOT_MODIFIED (null body)",
      );
  
      #t_debug $res->as_string;
  }
  
  
  {
      # modified
      my $if_modified_since = 'Sun, 29 Oct 2000 15:43:28 GMT';
      my $res = GET($url, 'If-Modified-Since' => $if_modified_since);
  
      ok t_cmp(
          200,
          $res->code,
          "test !HTTP_NOT_MODIFIED (200 status)",
      );
  
      ok t_cmp(
          '<html><head></head><body>Test</body></html>',
          $res->content,
          "test !HTTP_NOT_MODIFIED (normal body)",
      );
  
      #t_debug $res->as_string;
  }
  
  
  
  1.1                  modperl-2.0/ModPerl-Registry/t/cgi-bin/304.pl
  
  Index: 304.pl
  ===================================================================
  use APR::Date ();
  use Apache::Util ();
  use Apache::RequestRec ();
  
  use strict;
  use warnings FATAL => 'all';
  
  use constant FMT => '%a, %d %b %Y %H:%M:%S %Z';
  use constant GMT => 1;
  
  my $last_modified = "Sun, 29 Oct 2000 15:43:29 GMT";
  
  my $r = shift;
  
  my $date = Apache::Util::format_time($r->request_time, FMT, GMT, $r->pool);
  
  my $if_modified_since = $r->headers_in->{'If-Modified-Since'};
  
  my $status = 200;
  my $body   = '<html><head></head><body>Test</body></html>';
  
  if ($if_modified_since && APR::Date::parse_http($last_modified) 
      < APR::Date::parse_http($if_modified_since)) {
  
      $status = 304;
      $body   = '';
  }
  
  print <<HEADERS;
  Status: $status
  Date: $date
  Server: Apache/2.0.47
  Connection: close
  Last-Modified: $last_modified
  Content-Type: text/html; charset=iso-8859-1
  
  HEADERS
  
  print $body if length $body;
  
  
  

Reply via email to