httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Plüm, Rüdiger, VF-Group <ruediger.pl...@vodafone.com>
Subject New flag for RewriteCond: novary (NV)
Date Mon, 10 Sep 2007 11:04:19 GMT
A few days ago I stumbled across an undocumented feature of mod_rewrite.
If a HTTP header is used in a rewrite condition and this conditions becomes
true mod_rewrite adds this header to the Vary header.
Apart from being undocumented this seems to be a useful feature in order
to do caching correctly. But in my case this is not useful as the response
does NOT vary on the HTTP header involved (a Cookie in my case) because
the respective rewrite rule for this rewrite condition is used to do
some special failover stuff and the response always is the same. It is
only delivered by a different backend server.
So I propose to add the flag novary (NV) to RewriteCond in order to avoid adding
the respective HTTP header to the Vary header.

Index: modules/mappers/mod_rewrite.c
===================================================================
--- modules/mappers/mod_rewrite.c       (revision 574201)
+++ modules/mappers/mod_rewrite.c       (working copy)
@@ -135,6 +135,7 @@
 #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 @@
              || 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 @@
         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. */

Any comments?

And yes, before I commit this or a variant to trunk I will add some text to the rewrite
documenation :-).

Regards

Rüdiger

Mime
View raw message