stas        2004/08/01 17:36:43

  Added:       t/apache head_request.t
               t/response/TestApache head_request.pm
  Log:
  testing nuances of the HEAD request (e.g. when C-L header makes it through)
  
  Revision  Changes    Path
  1.1                  modperl-2.0/t/apache/head_request.t
  
  Index: head_request.t
  ===================================================================
  use strict;
  use warnings FATAL => 'all';
  
  # testing nuances of the HEAD request (e.g. when C-L header makes it
  # through)
  
  use Apache::Test;
  use Apache::TestUtil;
  use Apache::TestRequest;
  
  plan tests => 12;
  
  my $location = "/TestApache__head_request";
  
  {
      # if the response handler sends no data, and sets no C-L header,
      # the client doesn't get C-L header
      my $res = HEAD "$location";
      ok t_cmp $res->code, 200, "code";
      ok t_cmp $res->header('Content-Length'), undef, "C-L header";
      ok t_cmp $res->content, "", "content";
  }
  
  {
      # if the response handler sends no data, and sets C-L header,
      # the client doesn't get C-L header
      my $res = HEAD "$location?set_content_length";
      ok t_cmp $res->code, 200, "code";
      ok t_cmp $res->header('Content-Length'), undef, "C-L header";
      ok t_cmp $res->content, "", "content";
      t_debug $res->as_string;
  }
  
  {
      # if the response handler sends data, and sets no C-L header,
      # the client doesn't get C-L header
      my $res = HEAD "$location?send_body";
      ok t_cmp $res->code, 200, "code";
      ok t_cmp $res->header('Content-Length'), undef, "C-L header";
      ok t_cmp $res->content, "", "content";
      t_debug $res->as_string;
  }
  
  {
      # if the response handler sends data (e.g. one char string), and
      # sets C-L header, the client gets the C-L header
      my $res = HEAD "$location?send_body+set_content_length";
      ok t_cmp $res->code, 200, "code";
      ok t_cmp $res->header('Content-Length'), 25, "C-L header";
      ok t_cmp $res->content, "", "content";
      t_debug $res->as_string;
  }
  
  
  
  1.1                  modperl-2.0/t/response/TestApache/head_request.pm
  
  Index: head_request.pm
  ===================================================================
  package TestApache::head_request;
  
  # see the client for the comments
  
  use strict;
  use warnings FATAL => 'all';
  
  use Apache::RequestRec ();
  use Apache::RequestIO ();
  use Apache::Response ();
  
  use Apache::Const -compile => 'OK';
  
  my $body = "This is a response string";
  
  sub handler {
      my $r = shift;
  
      $r->content_type('text/plain');
  
      my $args = $r->args || '';
  
      if ($args =~ /set_content_length/) {
          $r->set_content_length(length $body);
      }
  
      if ($args =~ /send_body/) {
          # really could send just about anything, since Apache discards
          # the response body on HEAD requests
          $r->print($body);
      }
  
      Apache::OK;
  }
  
  1;
  
  
  

Reply via email to