From 6557d718a6519c9940c8e2785600ab9f17c0dcae Mon Sep 17 00:00:00 2001 From: Jim Jagielski Date: Mon, 13 Nov 2017 13:31:33 +0000 Subject: [PATCH] Merge r1811744 from trunk: core, mod_rewrite: introduce the 'redirect-keeps-vary' note to allow proper Vary header insertion when dealing with a RewriteRule in a directory context. This change is an attempt to fix a long standing problem, brought up while working on PR 58231. Our documentation clearly states the following: "If a HTTP header is used in a condition this header is added to the Vary header of the response in case the condition evaluates to true for the request." This is currently not true for RewriteCond/Rules working in a directory context, since when an internal redirect happens all the outstanding response headers get dropped. There might be a better solution so I am looking forward to hear more opinions and comments. My goal for a delicate change like this one would be to affect the least amount of configurations possible, without triggering unwanted side effects. If the solution is good for everybody tests will be written in the suite asap. Submitted by: elukey Reviewed by: elukey, icing, ylavic git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.4.x@1815100 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 4 ++++ STATUS | 7 ------- modules/http/http_request.c | 11 +++++++++++ modules/mappers/mod_rewrite.c | 2 ++ 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/CHANGES b/CHANGES index f65f33c298..4ce6d1126f 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,10 @@ -*- coding: utf-8 -*- Changes with Apache 2.4.30 + *) mod_rewrite, core: add the Vary header when a condition evaluates to true + and the related RewriteRule is used in a Directory context + (triggering an internal redirect). [Luca Toscano] + *) ab: Make the TLS layer aware that the underlying socket is nonblocking, and use/handle POLLOUT where needed to avoid busy IOs and recover write errors when appropriate. [Yann Ylavic] diff --git a/STATUS b/STATUS index d2f56d676c..13cb344c1c 100644 --- a/STATUS +++ b/STATUS @@ -118,13 +118,6 @@ RELEASE SHOWSTOPPERS: PATCHES ACCEPTED TO BACKPORT FROM TRUNK: [ start all new proposals below, under PATCHES PROPOSED. ] - *) core, mod_rewrite: introduce the 'keeps-redirect-vary' note in the internal redirect - workflow to keep the Vary headers set by RewriteCond/Rule - directives combinations in the directory context. PR: 58231 - trunk patch: https://svn.apache.org/r1811744 - 2.4.x: svn merge -c 1811744 ^/httpd/httpd/trunk . - +1: elukey, icing, ylavic - *) mod_macro: fix usability of globally defined macros in .htaccess files. PR 57525. trunk patch: http://svn.apache.org/r1813643 diff --git a/modules/http/http_request.c b/modules/http/http_request.c index 3f5393e04e..bc7ae22dc4 100644 --- a/modules/http/http_request.c +++ b/modules/http/http_request.c @@ -515,6 +515,7 @@ static request_rec *internal_internal_redirect(const char *new_uri, request_rec *r) { int access_status; request_rec *new; + const char *vary_header; if (ap_is_recursion_limit_exceeded(r)) { ap_die(HTTP_INTERNAL_SERVER_ERROR, r); @@ -578,6 +579,16 @@ static request_rec *internal_internal_redirect(const char *new_uri, if (location) apr_table_setn(new->headers_out, "Location", location); } + + /* A module (like mod_rewrite) can force an internal redirect + * to carry over the Vary header (if present). + */ + if (apr_table_get(r->notes, "redirect-keeps-vary")) { + if((vary_header = apr_table_get(r->headers_out, "Vary"))) { + apr_table_setn(new->headers_out, "Vary", vary_header); + } + } + new->err_headers_out = r->err_headers_out; new->trailers_out = apr_table_make(r->pool, 5); new->subprocess_env = rename_original_env(r->pool, r->subprocess_env); diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 05414c49cc..fb897a9760 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -5191,6 +5191,8 @@ static int hook_fixup(request_rec *r) } } + apr_table_setn(r->notes, "redirect-keeps-vary", ""); + /* now initiate the internal redirect */ rewritelog((r, 1, dconf->directory, "internal redirect with %s " "[INTERNAL REDIRECT]", r->filename)); -- 2.40.0