Hi Luca,

sorry for the delay (overwhelmed these times)...

On Mon, Dec 5, 2016 at 1:21 PM, Luca Toscano <toscano.l...@gmail.com> wrote:
>
>
> 2016-11-30 18:46 GMT+01:00 Luca Toscano <toscano.l...@gmail.com>:
>>
>> Hi everybody,
>>
>> while working on https://bz.apache.org/bugzilla/show_bug.cgi?id=51350 a
>> user asked why httpd send the "Content-Length: 0" header for HTTP 204
>> responses given the following statement in the RFC:
>>
>> https://tools.ietf.org/html/rfc7230#page-30
>> "A server MUST NOT send a Content-Length header field in any response with
>> a status code of 1xx (Informational) or 204 (No Content)."
>>
>> I tried with a simple PHP script returning an HTTP 204 header (via
>> mod_proxy_fcgi) and indeed I can see the Content-Length: 0. After a bit of
>> digging it seems that ap_content_length_filter in protocol.c adds the header
>> when it evaluates:
>>
>>         if (!(r->header_only
>>               && !r->bytes_sent
>>               && (r->sent_bodyct
>>                   || conf->http_cl_head_zero !=
>> AP_HTTP_CL_HEAD_ZERO_ENABLE
>>                   || apr_table_get(r->headers_out, "Content-Length")))) {
>>             ap_set_content_length(r, r->bytes_sent);
>>         }

How about adding (yet) another condition to the above:

Index: server/protocol.c
===================================================================
--- server/protocol.c    (revision 1772657)
+++ server/protocol.c    (working copy)
@@ -1766,7 +1766,9 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_content_le
          * such filters update or remove the C-L header, and just use it
          * if present.
          */
-        if (!(r->header_only
+        if (!((r->header_only
+               || r->status == HTTP_NO_CONTENT
+               || r->status == HTTP_NOT_MODIFIED)
               && !r->bytes_sent
               && (r->sent_bodyct
                   || conf->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_ENABLE
?

Regards,
Yann.

Reply via email to