httpd-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From n.@apache.org
Subject cvs commit: httpd-2.0/modules/mappers mod_rewrite.c
Date Sat, 24 Jan 2004 21:21:49 GMT
nd          2004/01/24 13:21:49

  Modified:    .        CHANGES
               modules/mappers mod_rewrite.c
  Log:
  Introduce the ability to force a content handler via
  the [handler=...] flag.
  
  Revision  Changes    Path
  1.1375    +3 -0      httpd-2.0/CHANGES
  
  Index: CHANGES
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/CHANGES,v
  retrieving revision 1.1374
  retrieving revision 1.1375
  diff -u -u -r1.1374 -r1.1375
  --- CHANGES	24 Jan 2004 02:02:09 -0000	1.1374
  +++ CHANGES	24 Jan 2004 21:21:49 -0000	1.1375
  @@ -2,6 +2,9 @@
   
     [Remove entries to the current 2.0 section below, when backported]
   
  +  *) mod_rewrite: Introduce the ability to force a content handler via
  +     the [handler=...] flag.  [André Malo]
  +
     *) mod_rewrite: Introduce the RewriteCond -x check, which returns
        true if the pattern is a file with execution permissions.
        [André Malo]
  
  
  
  1.246     +60 -29    httpd-2.0/modules/mappers/mod_rewrite.c
  
  Index: mod_rewrite.c
  ===================================================================
  RCS file: /home/cvs/httpd-2.0/modules/mappers/mod_rewrite.c,v
  retrieving revision 1.245
  retrieving revision 1.246
  diff -u -u -r1.245 -r1.246
  --- mod_rewrite.c	24 Jan 2004 02:02:09 -0000	1.245
  +++ mod_rewrite.c	24 Jan 2004 21:21:49 -0000	1.246
  @@ -161,6 +161,7 @@
   
   /* remembered mime-type for [T=...] */
   #define REWRITE_FORCED_MIMETYPE_NOTEVAR "rewrite-forced-mimetype"
  +#define REWRITE_FORCED_HANDLER_NOTEVAR  "rewrite-forced-handler"
   
   #define ENVVAR_SCRIPT_URL "SCRIPT_URL"
   #define REDIRECT_ENVVAR_SCRIPT_URL "REDIRECT_" ENVVAR_SCRIPT_URL
  @@ -305,7 +306,8 @@
       char      *output;               /* the Substitution string               */
       int        flags;                /* Flags which control the substitution  */
       char      *forced_mimetype;      /* forced MIME type of substitution      */
  -    int        forced_responsecode;  /* forced HTTP redirect response status  */
  +    char      *forced_handler;       /* forced content handler of subst.      */
  +    int        forced_responsecode;  /* forced HTTP response status           */
       data_item *env;                  /* added environment variables           */
       data_item *cookie;               /* added cookies                         */
       int        skip;                 /* number of next rules to skip          */
  @@ -3154,6 +3156,13 @@
           }
           break;
   
  +    case 'h':
  +    case 'H':
  +        if (!*key || !strcasecmp(key, "andler")) {         /* handler */
  +            cfg->forced_handler = val;
  +        }
  +        break;
  +
       case 'l':
       case 'L':
           if (!*key || !strcasecmp(key, "ast")) {            /* last */
  @@ -3287,6 +3296,7 @@
   
       /* arg3: optional flags field */
       newrule->forced_mimetype     = NULL;
  +    newrule->forced_handler      = NULL;
       newrule->forced_responsecode = HTTP_MOVED_TEMPORARILY;
       newrule->flags  = RULEFLAG_NONE;
       newrule->env = NULL;
  @@ -3494,6 +3504,41 @@
       return rc;
   }
   
  +/* check for forced type and handler */
  +static APR_INLINE void force_type_handler(rewriterule_entry *p,
  +                                          rewrite_ctx *ctx)
  +{
  +    char *expanded;
  +
  +    if (p->forced_mimetype) {
  +        expanded = do_expand(p->forced_mimetype, ctx);
  +
  +        if (*expanded) {
  +            ap_str_tolower(expanded);
  +
  +            rewritelog((ctx->r, 2, ctx->perdir, "remember %s to have MIME-type "
  +                        "'%s'", ctx->r->filename, expanded));
  +
  +            apr_table_setn(ctx->r->notes, REWRITE_FORCED_MIMETYPE_NOTEVAR,
  +                           expanded);
  +        }
  +    }
  +
  +    if (p->forced_handler) {
  +        expanded = do_expand(p->forced_handler, ctx);
  +
  +        if (*expanded) {
  +            ap_str_tolower(expanded);
  +
  +            rewritelog((ctx->r, 2, ctx->perdir, "remember %s to have "
  +                        "Content-handler '%s'", ctx->r->filename, expanded));
  +
  +            apr_table_setn(ctx->r->notes, REWRITE_FORCED_HANDLER_NOTEVAR,
  +                           expanded);
  +        }
  +    }
  +}
  +
   /*
    * Apply a single RewriteRule
    */
  @@ -3616,18 +3661,7 @@
   
       /* non-substitution rules ('RewriteRule <pat> -') end here. */
       if (p->flags & RULEFLAG_NOSUB) {
  -        if (p->forced_mimetype) {
  -            char *type = do_expand(p->forced_mimetype, ctx);
  -
  -            if (*type) {
  -                ap_str_tolower(type);
  -
  -                rewritelog((r, 2, ctx->perdir, "remember %s to have MIME-type "
  -                            "'%s'", r->filename, type));
  -
  -                apr_table_setn(r->notes, REWRITE_FORCED_MIMETYPE_NOTEVAR, type);
  -            }
  -        }
  +        force_type_handler(p, ctx);
   
           if (p->flags & RULEFLAG_STATUS) {
               rewritelog((r, 2, ctx->perdir, "forcing responsecode %d for %s",
  @@ -3709,18 +3743,7 @@
       }
   
       /* Finally remember the forced mime-type */
  -    if (p->forced_mimetype) {
  -        char *type = do_expand(p->forced_mimetype, ctx);
  -
  -        if (*type) {
  -            ap_str_tolower(type);
  -
  -            rewritelog((r, 2, ctx->perdir, "remember %s to have MIME-type '%s'",
  -                        r->filename, type));
  -
  -            apr_table_setn(r->notes, REWRITE_FORCED_MIMETYPE_NOTEVAR, type);
  -        }
  -    }
  +    force_type_handler(p, ctx);
   
       /* Puuhhhhhhhh... WHAT COMPLICATED STUFF ;_)
        * But now we're done for this particular rule.
  @@ -4529,23 +4552,31 @@
   
   /*
    * MIME-type hook
  - * [T=...] in server-context
  + * [T=...,H=...] execution
    */
   static int hook_mimetype(request_rec *r)
   {
       const char *t;
   
  +    /* type */
       t = apr_table_get(r->notes, REWRITE_FORCED_MIMETYPE_NOTEVAR);
  -
       if (t && *t) {
           rewritelog((r, 1, NULL, "force filename %s to have MIME-type '%s'",
                       r->filename, t));
   
           ap_set_content_type(r, t);
  -        return OK;
       }
   
  -    return DECLINED;
  +    /* handler */
  +    t = apr_table_get(r->notes, REWRITE_FORCED_HANDLER_NOTEVAR);
  +    if (t && *t) {
  +        rewritelog((r, 1, NULL, "force filename %s to have the "
  +                    "Content-handler '%s'", r->filename, t));
  +
  +        r->handler = t;
  +    }
  +
  +    return OK;
   }
   
   /* check whether redirect limit is reached */
  
  
  

Mime
View raw message