]> granicus.if.org Git - apache/commitdiff
mod_rewrite/core: avoid the 'Vary: Host' header
authorLuca Toscano <elukey@apache.org>
Mon, 18 Sep 2017 17:08:54 +0000 (17:08 +0000)
committerLuca Toscano <elukey@apache.org>
Mon, 18 Sep 2017 17:08:54 +0000 (17:08 +0000)
In PR 58231 is was brought up that httpd adds the
Vary: Host header whenever a condition is set to true
in mod_rewrite or in an <If> block.

The https://tools.ietf.org/html/rfc7231#section-7.1.4
section seems to disallow this use case:

"The "Vary" header field in a response describes "
"what parts of a request message, "
"aside from the method, Host header field, [...]"

I had a chat with the folks in #traffic-server and
they don't see much point in having a Vary: Host header,
plus it was reported that Varnish doesn't like it very
much (namely it does not cache the response when
it sees the header, links of the report in the PR).

I don't see much value in this behavior of httpd so
I am inclined to remove this response header value,
but I'd be glad to get a more experienced opinion.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@1808746 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
modules/mappers/mod_rewrite.c
server/util_expr_eval.c

diff --git a/CHANGES b/CHANGES
index 52c460fab44acd367bd4b08f2d07c29d2cf470b5..fc03f9fbee6a4a6f393b5a29d49ebd2d931b966a 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,9 @@
                                                          -*- coding: utf-8 -*-
 Changes with Apache 2.5.0
 
+  *) mod_rewrite, core: Avoid the 'Vary: Host' response header when HTTP_HOST is
+     used in a condition that evaluates to true. PR 58231 [Luca Toscano]
+
   *) mod_md: v0.9.6: a "MDRequireHttps permament" configured domain automatically sends out
      HSTS (rfc 6797) headers in https: responses. [Stefan Eissing]
 
index 9647c6f55b7779e6419b5fdb9452092c13f2666a..e94a65641c99ccd34d8a3784e3b4ba2e14dd6f4a 100644 (file)
@@ -2035,7 +2035,10 @@ static char *lookup_variable(char *var, rewrite_ctx *ctx)
 
             case 'S':
                 if (!strcmp(var, "HTTP_HOST")) {
-                    result = lookup_header("Host", ctx);
+                    /* Skip the 'Vary: Host' header combination
+                     * as indicated in rfc7231 section-7.1.4
+                     */
+                    result = apr_table_get(ctx->r->headers_in, "Host");
                 }
                 break;
 
index 9f3640481daef2bdb9bd6e87b7995ed5b690df55..bf579d70cdfdd127a17d5e589528556f3699374b 100644 (file)
@@ -1606,7 +1606,12 @@ static const char *req_header_var_fn(ap_expr_eval_ctx_t *ctx, const void *data)
         return "";
 
     name = req_header_header_names[index];
-    add_vary(ctx, name);
+    /* Skip the 'Vary: Host' header combination
+     * as indicated in rfc7231 section-7.1.4
+     */
+    if (strcmp(name, "Host")){
+        add_vary(ctx, name);
+    }
     return apr_table_get(ctx->r->headers_in, name);
 }