>> ??? I do not know what you mean, my GET request _has_ a content-lenght
>> header! For HEAD, I just do not calculate the expencive data for my body.

that is exactly what I mean - if you include a C-L header on a GET then you
are supposed to have one for a HEAD request as well, expensive or not.  HEAD
is supposed to be exactly the same as a GET in all respects except that it
does not have a message body.

>>
>> I just missed the content-length header on HEAD requests that is
>> delivered on GET.
> 
> 
> Geoff, see the t/apache/head_request.t test I've added last night. If
> you don't send a body, Apache strips the C-L header for HEAD requests.
> Sending at least 1 byte works as a workaround, but it smells like a bug
> in Apache.

yes, clearly there is a bug in there, but not where you think - what is
important is that apache needs to do the same thing on GET as HEAD, not that
there is no C-L generated for contentless HEAD requests.  this patch more
accurately represents the real bug which, IIRC, httpd is already aware of
(at least I'm recalling discussion about a C-L of 0).

--Geoff
Index: t/apache/head_request.t
===================================================================
RCS file: /home/cvs/modperl-2.0/t/apache/head_request.t,v
retrieving revision 1.2
diff -u -r1.2 head_request.t
--- t/apache/head_request.t	2 Aug 2004 03:38:30 -0000	1.2
+++ t/apache/head_request.t	2 Aug 2004 17:30:54 -0000
@@ -8,42 +8,54 @@
 use Apache::TestUtil;
 use Apache::TestRequest;
 
-plan tests => 12;
+plan tests => 12 * 2, todo => [2,5];
 
 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";
-}
-
-{
-    # 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";
-}
-
-{
-    # 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";
+no strict qw(refs);
+foreach my $method qw(GET HEAD) {
+
+    {
+        # if the response handler sends no data, and sets no C-L header,
+        # the client doesn't get C-L header
+        my $uri = $location;
+        my $res = $method->($uri);
+        ok t_cmp $res->code, 200, "$method $uri code";
+        ok t_cmp $res->header('Content-Length'), undef, "$method $uri C-L header";
+        ok t_cmp $res->content, "", "$method $uri content";
+    }
+
+    {
+        # if the response handler sends no data, and sets C-L header,
+        # the client doesn't get C-L header
+        my $uri = "$location?set_content_length";
+        my $res = $method->($uri);
+        ok t_cmp $res->code, 200, "$method $uri code";
+        ok t_cmp $res->header('Content-Length'), undef, "$method $uri C-L header";
+        ok t_cmp $res->content, "", "$method $uri content";
+    }
+
+    {
+        # if the response handler sends data, and sets no C-L header,
+        # the client doesn't get C-L header
+        my $uri = "$location?send_body";
+        my $res = $method->($uri);
+        ok t_cmp $res->code, 200, "$method $uri code";
+        ok t_cmp $res->header('Content-Length'), undef, "$method $uri C-L header";
+
+        my $content = $method eq 'GET' ? 'This is a response string' : '';
+        ok t_cmp $res->content, $content, "$method $uri content";
+    }
+
+    {
+        # if the response handler sends data (e.g. one char string), and
+        # sets C-L header, the client gets the C-L header
+        my $uri = "$location?send_body+set_content_length";
+        my $res = $method->($uri);
+        ok t_cmp $res->code, 200, "$method $uri code";
+        ok t_cmp $res->header('Content-Length'), 25, "$method $uri C-L header";
+
+        my $content = $method eq 'GET' ? 'This is a response string' : '';
+        ok t_cmp $res->content, $content, "$method $uri content";
+    }
 }

-- 
Report problems: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html
List etiquette: http://perl.apache.org/maillist/email-etiquette.html

Reply via email to