]> granicus.if.org Git - apache/commitdiff
allow setting of any valid HTTP response code via R flag.
authorAndré Malo <nd@apache.org>
Tue, 13 Jan 2004 18:17:55 +0000 (18:17 +0000)
committerAndré Malo <nd@apache.org>
Tue, 13 Jan 2004 18:17:55 +0000 (18:17 +0000)
except for redirects this implies [L] and match-only (no
substitution).

PR: 25917

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

CHANGES
modules/mappers/mod_rewrite.c

diff --git a/CHANGES b/CHANGES
index bf5c2040417df185920a8bd33829d97cb9e9ea34..90b3d33c71fde9a7cca90743d0f3695fad781ebb 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -2,6 +2,9 @@ Changes with Apache 2.1.0-dev
 
   [Remove entries to the current 2.0 section below, when backported]
 
+  *) mod_rewrite: Allow setting of any valid HTTP response code.
+     PR 25917.  [André Malo]
+
   *) mod_rewrite: Cookie creation now works locale independent.
      [André Malo]
 
index 43af23b83aec7ef940ef15fb6f55e240e6014c69..4de64ea062ba42a0c60a2be4fce1eff9d4db4c57 100644 (file)
 #define RULEFLAG_NOCASE             1<<12
 #define RULEFLAG_NOESCAPE           1<<13
 #define RULEFLAG_NOSUB              1<<14
+#define RULEFLAG_STATUS             1<<15
 
 /* return code of the rewrite rule
  * the result may be escaped - or not
  */
 #define ACTION_NORMAL               1<<0
 #define ACTION_NOESCAPE             1<<1
+#define ACTION_STATUS               1<<2
 
 
 #define MAPTYPE_TXT                 1<<0
@@ -3211,9 +3213,19 @@ static const char *cmd_rewriterule_setflag(apr_pool_t *p, void *_cfg,
                 }
                 else if (apr_isdigit(*val)) {
                     status = atoi(val);
+                    if (status != HTTP_INTERNAL_SERVER_ERROR) {
+                        int idx =
+                            ap_index_of_response(HTTP_INTERNAL_SERVER_ERROR);
+
+                        if (ap_index_of_response(status) == idx) {
+                            return apr_psprintf(p, "RewriteRule: invalid HTTP "
+                                                   "response code '%s' for "
+                                                   "flag 'R'",
+                                                val);
+                        }
+                    }
                     if (!ap_is_HTTP_REDIRECT(status)) {
-                        return "RewriteRule: invalid HTTP response code "
-                               "for flag 'R'";
+                        cfg->flags |= (RULEFLAG_STATUS | RULEFLAG_NOSUB);
                     }
                 }
                 cfg->forced_responsecode = status;
@@ -3608,6 +3620,13 @@ static int apply_rewrite_rule(rewriterule_entry *p, rewrite_ctx *ctx)
             }
         }
 
+        if (p->flags & RULEFLAG_STATUS) {
+            rewritelog((r, 2, ctx->perdir, "forcing responsecode %d for %s",
+                        p->forced_responsecode, r->filename));
+
+            r->status = p->forced_responsecode;
+        }
+
         return 2;
     }
 
@@ -3756,7 +3775,14 @@ static int apply_rewrite_list(request_rec *r, apr_array_header_t *rewriterules,
             }
 
             /*
-             *  Indicate a change if this was not a match-only rule.
+             * The rule sets the response code (implies match-only)
+             */
+            if (p->flags & RULEFLAG_STATUS) {
+                return ACTION_STATUS;
+            }
+
+            /*
+             * Indicate a change if this was not a match-only rule.
              */
             if (rc != 2) {
                 changed = ((p->flags & RULEFLAG_NOESCAPE)
@@ -4095,8 +4121,16 @@ static int hook_uri2file(request_rec *r)
 
     if (rulestatus) {
         unsigned skip;
-        apr_size_t flen = strlen(r->filename);
+        apr_size_t flen;
+
+        if (ACTION_STATUS == rulestatus) {
+            int n = r->status;
 
+            r->status = HTTP_OK;
+            return n;
+        }
+
+        flen = strlen(r->filename);
         if (flen > 6 && strncmp(r->filename, "proxy:", 6) == 0) {
             /* it should be go on as an internal proxy request */
 
@@ -4334,8 +4368,15 @@ static int hook_fixup(request_rec *r)
     rulestatus = apply_rewrite_list(r, dconf->rewriterules, dconf->directory);
     if (rulestatus) {
         unsigned skip;
-        l = strlen(r->filename);
 
+        if (ACTION_STATUS == rulestatus) {
+            int n = r->status;
+
+            r->status = HTTP_OK;
+            return n;
+        }
+
+        l = strlen(r->filename);
         if (l > 6 && strncmp(r->filename, "proxy:", 6) == 0) {
             /* it should go on as an internal proxy request */