On Wed, Apr 29, 2015 at 2:46 PM, Eric Covener <cove...@gmail.com> wrote:
> On Wed, Apr 29, 2015 at 8:19 AM, Yann Ylavic <ylavic....@gmail.com> wrote:
>> Hence how about removing this whole block (is there any module today
>> "outsmarting" httpd that cannot be considered as buggy?) or least
>> disable it for forwarded responses, eg:
>>
>> Index: modules/http/http_filters.c
>> ===================================================================
>> --- modules/http/http_filters.c    (revision 1676716)
>> +++ modules/http/http_filters.c    (working copy)
>> @@ -1292,6 +1292,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_heade
>>       * The default (unset) behavior is to squelch the C-L in this case.
>>       */
>>      if (r->header_only
>> +        && !r->proxyreq
>>          && (clheader = apr_table_get(r->headers_out, "Content-Length"))
>>          && !strcmp(clheader, "0")
>>          && conf->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_ENABLE) {
>
>
> Maybe we could remember here if the CL was set by
> ap_content_length_filter or someone else?

The patch below tries your proposal...

Set a note If we detect that the header_only CL is from the origin in
ap_content_length_filter(), and don't strip the Content-Length if that
note is set in ap_http_header_filter().
We could also avoid the note by setting r->clength = -1 instead in
ap_content_length_filter().

This should work both with buggy modules and the normal cases (including proxy).
I guess we wouldn't need HttpContentLengthHeadZero from r1554303
anymore (and several third-party patches that simply disable the whole
unconditionally).

Do it sound better?

Index: server/protocol.c
===================================================================
--- server/protocol.c    (revision 1676716)
+++ server/protocol.c    (working copy)
@@ -1533,7 +1533,7 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_content_le
      * We can only set a C-L in the response header if we haven't already
      * sent any buckets on to the next output filter for this request.
      */
-    if (ctx->data_sent == 0 && eos &&
+    if (ctx->data_sent == 0 && eos) {
         /* don't whack the C-L if it has already been set for a HEAD
          * by something like proxy.  the brigade only has an EOS bucket
          * in this case, making r->bytes_sent zero.
@@ -1544,9 +1544,13 @@ 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.
          */
-        !(r->header_only && r->bytes_sent == 0 &&
-            apr_table_get(r->headers_out, "Content-Length"))) {
-        ap_set_content_length(r, r->bytes_sent);
+        if (r->header_only && r->bytes_sent == 0 &&
+                apr_table_get(r->headers_out, "Content-Length")) {
+            apr_table_setn(r->notes, "origin-ho", "1");
+        }
+        else {
+            ap_set_content_length(r, r->bytes_sent);
+        }
     }

     ctx->data_sent = 1;
Index: modules/http/http_filters.c
===================================================================
--- modules/http/http_filters.c    (revision 1676716)
+++ modules/http/http_filters.c    (working copy)
@@ -1292,9 +1292,11 @@ AP_CORE_DECLARE_NONSTD(apr_status_t) ap_http_heade
      * The default (unset) behavior is to squelch the C-L in this case.
      */
     if (r->header_only
-        && (clheader = apr_table_get(r->headers_out, "Content-Length"))
-        && !strcmp(clheader, "0")
-        && conf->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_ENABLE) {
+            && !r->clength
+            && !apr_table_get(r->notes, "origin-ho")
+            && (clheader = apr_table_get(r->headers_out, "Content-Length"))
+            && !strcmp(clheader, "0")
+            && conf->http_cl_head_zero != AP_HTTP_CL_HEAD_ZERO_ENABLE) {
         apr_table_unset(r->headers_out, "Content-Length");
     }

--

Reply via email to