From ce9eaa96e8ee737457bee00a532b4cbcb334b3fa Mon Sep 17 00:00:00 2001 From: Ruediger Pluem Date: Tue, 11 Sep 2007 20:15:54 +0000 Subject: [PATCH] * Add the novary flag to RewriteCond in order to prevent the appending of HTTP headers used in a rewrite condition to the Vary header of the response. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@574684 13f79535-47bb-0310-9956-ffa450edef68 --- CHANGES | 3 +++ docs/manual/mod/mod_rewrite.xml | 20 +++++++++++++++++++- modules/mappers/mod_rewrite.c | 11 +++++++++++ 3 files changed, 33 insertions(+), 1 deletion(-) diff --git a/CHANGES b/CHANGES index 01ac0bdcb0..07f0d6cf54 100644 --- a/CHANGES +++ b/CHANGES @@ -2,6 +2,9 @@ Changes with Apache 2.3.0 [ When backported to 2.2.x, remove entry from this file ] + *) mod_rewrite: Add the novary flag to RewriteCond. + [Ruediger Pluem] + *) Don't send spurious "100 Continue" response lines. PR 38014 [Basant Kumar Kukreja ] diff --git a/docs/manual/mod/mod_rewrite.xml b/docs/manual/mod/mod_rewrite.xml index 317e0106a7..b7649afc41 100644 --- a/docs/manual/mod/mod_rewrite.xml +++ b/docs/manual/mod/mod_rewrite.xml @@ -848,7 +848,15 @@ Result: value of a header sent in the HTTP request. Example: %{HTTP:Proxy-Connection} is the value of the HTTP header - ``Proxy-Connection:''. + ``Proxy-Connection:''. +

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 + to true for the request. It is not added if the + condition evaluates to false for the request. Adding the HTTP header + to the Vary header of the response is needed for proper caching.

+

It has to be kept in mind that conditions follow a short circuit + logic in the case of the 'ornext|OR' flag + so that certain conditions might not be evaluated at all.

  • %{LA-U:variable} can be used for look-aheads which perform @@ -1008,6 +1016,16 @@ RewriteRule ...some special stuff for any of these hosts... Without this flag you would have to write the condition/rule pair three times.
  • + +
  • 'novary|NV' + (no vary)
    + If a HTTP header is used in the condition, this flag prevents + this header from being added to the Vary header of the response.
    + Using this flag might break proper caching of the response if + the representation of this response varies on the value of this header. + So this flag should be only used if the meaning of the Vary header + is well understood. +
  • diff --git a/modules/mappers/mod_rewrite.c b/modules/mappers/mod_rewrite.c index 83d55ca4cf..e76b165f57 100644 --- a/modules/mappers/mod_rewrite.c +++ b/modules/mappers/mod_rewrite.c @@ -135,6 +135,7 @@ static void (*dbd_prepare)(server_rec*, const char*, const char*) = NULL; #define CONDFLAG_NOCASE 1<<1 #define CONDFLAG_NOTMATCH 1<<2 #define CONDFLAG_ORNEXT 1<<3 +#define CONDFLAG_NOVARY 1<<4 #define RULEFLAG_NONE 1<<0 #define RULEFLAG_FORCEREDIRECT 1<<1 @@ -3207,6 +3208,10 @@ static const char *cmd_rewritecond_setflag(apr_pool_t *p, void *_cfg, || strcasecmp(key, "OR") == 0 ) { cfg->flags |= CONDFLAG_ORNEXT; } + else if ( strcasecmp(key, "novary") == 0 + || strcasecmp(key, "NV") == 0 ) { + cfg->flags |= CONDFLAG_NOVARY; + } else { return apr_pstrcat(p, "RewriteCond: unknown flag '", key, "'", NULL); } @@ -3908,6 +3913,12 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx) rewritecond_entry *c = &conds[i]; rc = apply_rewrite_cond(c, ctx); + /* + * Reset vary_this if the novary flag is set for this condition. + */ + if (c->flags & CONDFLAG_NOVARY) { + ctx->vary_this = NULL; + } if (c->flags & CONDFLAG_ORNEXT) { if (!rc) { /* One condition is false, but another can be still true. */ -- 2.40.0