diff options
-rw-r--r-- | docs/manual/mod/mod_mime.html | 75 | ||||
-rw-r--r-- | modules/http/mod_mime.c | 39 |
2 files changed, 101 insertions, 13 deletions
diff --git a/docs/manual/mod/mod_mime.html b/docs/manual/mod/mod_mime.html index 058ff4ab09..c152f414fc 100644 --- a/docs/manual/mod/mod_mime.html +++ b/docs/manual/mod/mod_mime.html @@ -46,16 +46,15 @@ which determines how the document will be processed within the server. The directives <a href="#addcharset">AddCharset</a>, <A HREF="#addencoding">AddEncoding</A>, <A HREF="#addhandler">AddHandler</A>, -<A HREF="#addlanguage">AddLanguage</A> and <A HREF="#addtype">AddType</A> -are all used to map file extensions onto the meta-information for that -file. Respectively they set the character set, content-encoding, handler, -content-language, and MIME-type (content-type) of documents. The -directive <A HREF="#typesconfig">TypesConfig</A> is used to specify a -file which also maps extensions onto MIME types. The directives <A -HREF="#forcetype">ForceType</A> and <A -HREF="#sethandler">SetHandler</A> are used to associated all the files -in a given location (<EM>e.g.</EM>, a particular directory) onto a particular -MIME type or handler. +A HREF="#SetFilter">SetFilter</A>, <A HREF="#addlanguage">AddLanguage</A> +and <A HREF="#addtype">AddType</A> are all used to map file extensions onto +the meta-information for that file. Respectively they set the character set, +content-encoding, handler, content-language, and MIME-type (content-type) of +documents. The directive <A HREF="#typesconfig">TypesConfig</A> is used to +specify a file which also maps extensions onto MIME types. The directives +<A HREF="#forcetype">ForceType</A> and <A HREF="#sethandler">SetHandler</A> +are used to associated all the files in a given location (<EM>e.g.</EM>, a +particular directory) onto a particular MIME type or handler. <P> @@ -68,6 +67,7 @@ copies may still be used by a client or proxy, with the previous headers. <li><a href="#addcharset">AddCharset</a></li> <LI><A HREF="#addencoding">AddEncoding</A> <LI><A HREF="#addhandler">AddHandler</A> +<LI><A HREF="#setfilter">SetFilter</A> <LI><A HREF="#addlanguage">AddLanguage</A> <LI><A HREF="#addtype">AddType</A> <LI><A HREF="#defaultlanguage">DefaultLanguage</A> @@ -339,6 +339,61 @@ HREF="./mod_negotiation.html">mod_negotiation</A> <HR> +<H2><A NAME="setfilter">SetFilter</A> directive</H2> +<!--%plaintext <?INDEX {\tt SetFilter} directive> --> +<A + HREF="directive-dict.html#Syntax" + REL="Help" +><STRONG>Syntax:</STRONG></A> SetFilter <EM>Assign filters based on MIME-type...</EM><BR> +<A + HREF="directive-dict.html#Context" + REL="Help" +><STRONG>Context:</STRONG></A> server config, virtual host, directory, .htaccess<BR> +<A + HREF="directive-dict.html#Override" + REL="Help" +><STRONG>Override:</STRONG></A> FileInfo<BR> +<A + HREF="directive-dict.html#Status" + REL="Help" +><STRONG>Status:</STRONG></A> Base<BR> +<A + HREF="directive-dict.html#Module" + REL="Help" +><STRONG>Module:</STRONG></A> mod_mime + +<P> +The SetFilter directive maps a filter stack to the specified content +type. +</P> +<P> +Example: <BLOCKQUOTE><CODE> +SetFilter server-parsed INCLUDES CACHE +</CODE></BLOCKQUOTE> +</P> +<P> +Then any document with the server-parsed MIME-type will pass through the +INCLUDES and CACHE filters. The filters are added in the same order that +they are specified in the config file. +</P> +<P> +This can be very powerful when combined with either the <A HREF="#addtype"> +AddType</A> or <A HREF="#addhandler">AddHandler</A> directives. This allows +you to specify an extension for a MIME-type and a set of filters for files +with those extensions to be passed through +</P> +<PRE> +AddHandler server-parsed .shtml +SetFilter server-parsed INCLUDES +</PRE> +<P> +documents with the extension "<CODE>.shtml</CODE>" would be passed through +the INCLUDES filter. +</P> +<P> + +<HR> + <H2><A NAME="addtype">AddType</A> directive</H2> <!--%plaintext <?INDEX {\tt AddType} directive> --> <A diff --git a/modules/http/mod_mime.c b/modules/http/mod_mime.c index de911ba031..32ecc16b1e 100644 --- a/modules/http/mod_mime.c +++ b/modules/http/mod_mime.c @@ -101,11 +101,11 @@ typedef struct { apr_table_t *language_types; /* Added with AddLanguage... */ apr_table_t *handlers; /* Added with AddHandler... */ apr_table_t *charset_types; /* Added with AddCharset... */ - apr_array_header_t *handlers_remove; /* List of handlers to remove */ - apr_array_header_t *types_remove; /* List of MIME types to remove */ + 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 @@ static void *create_mime_dir_config(apr_pool_t *p, char *dummy) 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 @@ static void *merge_mime_dir_configs(apr_pool_t *p, void *basev, void *addv) 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 @@ static const char *add_handler(cmd_parms *cmd, void *m_, const char *hdlr_, 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 @@ AP_INIT_ITERATE2("AddLanguage", add_language, NULL, OR_FILEINFO, "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 @@ static int find_ct(request_rec *r) 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 = { |