httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Bill Stoddard" <b...@wstoddard.com>
Subject Re: [PATCH] Filtering based on Mime-Type
Date Sun, 19 Nov 2000 14:20:51 GMT
+1
----- Original Message ----- 
From: <rbb@covalent.net>
To: <new-httpd@apache.org>
Sent: Sunday, November 19, 2000 2:45 AM
Subject: [PATCH] Filtering based on Mime-Type


> 
> Here is a patch that implements mime-based filtering.  In the config file,
> the adming puts:
> 
> SetFilter mime/type Filter1 Filter2 filter3 ...
> 
> When the server goes to serve something of a given type, the specified
> filters are added.  I know there are some people who have very specific
> ideas of how this should be done, and I didn't want to upset anybody by
> committing this the day before the alpha was released.  If people want me
> to add this before I roll tomorrow I will.  If not, this will be the first
> commit after I tag.
> 
> Ryan
> 
> ? build.log
> ? build.err
> ? lib/apr/test/build.log
> ? lib/apr/test/build.err
> ? modules/proxy/.libs
> ? modules/proxy/libapachemod_proxy.la
> Index: CHANGES
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/CHANGES,v
> retrieving revision 1.341
> diff -u -d -b -w -u -r1.341 CHANGES
> --- CHANGES 2000/11/18 20:52:28 1.341
> +++ CHANGES 2000/11/19 07:34:51
> @@ -1,4 +1,8 @@
>  Changes with Apache 2.0a8
> +  *) Add a directive to mod_mime so that filters can be associated with
> +     a given mime-type.
> +     [Ryan Bloom]
> +
>    *) Get multi-views working again.  We were setting the path_info
>       field incorrectly if we couldn't find the specified file.
>       [Ryan Bloom]
> Index: modules/standard/mod_mime.c
> ===================================================================
> RCS file: /home/cvs/apache-2.0/src/modules/standard/mod_mime.c,v
> retrieving revision 1.28
> diff -u -d -b -w -u -r1.28 mod_mime.c
> --- modules/standard/mod_mime.c 2000/10/16 06:05:06 1.28
> +++ modules/standard/mod_mime.c 2000/11/19 07:35:57
> @@ -101,11 +101,11 @@
>      apr_table_t *language_types;      /* Added with AddLanguage... */
>      apr_table_t *handlers;            /* Added with AddHandler...  */
>      apr_table_t *charset_types;       /* Added with AddCharset... */       
> +    apr_table_t *filter_names;        /* Added with SetFilterStack... */       
>      apr_array_header_t *handlers_remove;     /* List of handlers to remove */
>      apr_array_header_t *types_remove;       /* List of MIME types to remove */
>      apr_array_header_t *encodings_remove; /* List of encodings to remove */
>  
> -
>      char *type;                 /* Type forced with ForceType  */
>      char *handler;              /* Handler forced with SetHandler */
>      char *default_language;     /* Language if no AddLanguage ext found */
> @@ -142,6 +142,7 @@
>      new->encoding_types = apr_make_table(p, 4);
>      new->charset_types = apr_make_table(p, 4);
>      new->language_types = apr_make_table(p, 4);
> +    new->filter_names = apr_make_table(p, 4);
>      new->handlers = apr_make_table(p, 4);
>      new->handlers_remove = apr_make_array(p, 4, sizeof(attrib_info));
>      new->types_remove = apr_make_array(p, 4, sizeof(attrib_info));
> @@ -171,6 +172,8 @@
>      base->charset_types);
>      new->language_types = apr_overlay_tables(p, add->language_types,
>                                           base->language_types);
> +    new->filter_names = apr_overlay_tables(p, add->filter_names,
> +                                   base->filter_names);
>      new->handlers = apr_overlay_tables(p, add->handlers,
>                                     base->handlers);
>  
> @@ -266,6 +269,17 @@
>      return NULL;
>  }
>  
> +static const char *set_filter(cmd_parms *cmd, void *m_, const char *ct_,
> +                            const char *filt)
> +{
> +    mime_dir_config *m=m_;
> +    char *ct=apr_pstrdup(cmd->pool,ct_);
> +
> +    ap_str_tolower(ct);
> +    apr_table_addn(m->filter_names, ct, filt);
> +    return NULL;
> +}
> +
>  /*
>   * Note handler names that should be un-added for this location.  This
>   * will keep the association from being inherited, as well, but not
> @@ -342,6 +356,8 @@
>       "a language (e.g., fr), followed by one or more file extensions"),
>  AP_INIT_ITERATE2("AddHandler", add_handler, NULL, OR_FILEINFO,
>       "a handler name followed by one or more file extensions"),
> +AP_INIT_ITERATE2("SetFilter", set_filter, NULL, OR_FILEINFO, 
> +     "a mime type followed by one or more filters"),
>  AP_INIT_TAKE1("ForceType", ap_set_string_slot_lower, 
>       (void *)XtOffsetOf(mime_dir_config, type), OR_FILEINFO,
>       "a media type"),
> @@ -808,10 +824,27 @@
>      return OK;
>  }
>  
> +static int filter_chain(void *input, const char *key, const char *val)
> +{
> +    request_rec *r = input;
> +
> +    ap_add_output_filter(val, NULL, r, r->connection);
> +    return 1;
> +}
> +
> +static void mime_insert_filter(request_rec *r)
> +{
> +    mime_dir_config *conf =
> +    (mime_dir_config *) ap_get_module_config(r->per_dir_config, &mime_module);
> +
> +    apr_table_do(filter_chain, r, conf->filter_names, r->content_type, NULL);
> +}
> +
>  static void register_hooks(void)
>  {
>      ap_hook_type_checker(find_ct,NULL,NULL,AP_HOOK_MIDDLE);
>      ap_hook_post_config(mime_post_config,NULL,NULL,AP_HOOK_MIDDLE);
> +    ap_hook_insert_filter(mime_insert_filter, NULL, NULL, AP_HOOK_MIDDLE);
>  }
>  
>  module AP_MODULE_DECLARE_DATA mime_module = {
> 
> 
> _______________________________________________________________________________
> Ryan Bloom                        rbb@apache.org
> 406 29th St.
> San Francisco, CA 94131
> -------------------------------------------------------------------------------
> 


Mime
View raw message