From a17358b2807b1558f72dc3a78292bb2b76ba100f Mon Sep 17 00:00:00 2001
From: Ryan Bloom
Date: Sun, 19 Nov 2000 16:55:11 +0000
Subject: [PATCH] Add a directive to mod_mime which allows people to configure
a filter stack for a given mime-type.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@87026 13f79535-47bb-0310-9956-ffa450edef68
---
docs/manual/mod/mod_mime.html | 75 ++++++++++++++++++++++++++++++-----
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 AddCharset,
AddEncoding, AddHandler,
-AddLanguage and AddType
-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 TypesConfig is used to specify a
-file which also maps extensions onto MIME types. The directives ForceType and SetHandler are used to associated all the files
-in a given location (e.g., a particular directory) onto a particular
-MIME type or handler.
+A HREF="#SetFilter">SetFilter, AddLanguage
+and AddType 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 TypesConfig is used to
+specify a file which also maps extensions onto MIME types. The directives
+ForceType and SetHandler
+are used to associated all the files in a given location (e.g., a
+particular directory) onto a particular MIME type or handler.
@@ -68,6 +67,7 @@ copies may still be used by a client or proxy, with the previous headers.
AddCharset
AddEncoding
AddHandler
+SetFilter
AddLanguage
AddType
DefaultLanguage
@@ -339,6 +339,61 @@ HREF="./mod_negotiation.html">mod_negotiation
+
+
+Syntax: SetFilter Assign filters based on MIME-type...
+Context: server config, virtual host, directory, .htaccess
+Override: FileInfo
+Status: Base
+Module: mod_mime
+
+
+The SetFilter directive maps a filter stack to the specified content
+type.
+
+
+Example:
+SetFilter server-parsed INCLUDES CACHE
+
+
+
+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.
+
+
+This can be very powerful when combined with either the
+AddType or AddHandler 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
+
+
+AddHandler server-parsed .shtml
+SetFilter server-parsed INCLUDES
+
+
+documents with the extension ".shtml
" would be passed through
+the INCLUDES filter.
+
+
+
+
+
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 = {
--
2.40.0