From: Jim Jagielski Date: Wed, 29 Aug 2007 22:37:26 +0000 (+0000) Subject: Merge r570532, r570535, r570558 from trunk: X-Git-Tag: 2.2.6~81 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=684cb7cd712d7ac5f3b56edc0787e6a9ab32bbda;p=thirdparty%2Fapache%2Fhttpd.git Merge r570532, r570535, r570558 from trunk: IndexOptions ContentType=text/html Charset=UTF-8 magic. Document new IndexOptions options Make Bill happy ;) Submitted by: jim Reviewed by: root git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/branches/2.2.x@570962 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/CHANGES b/CHANGES index aa5cf68f17e..95fc7eaea5d 100644 --- a/CHANGES +++ b/CHANGES @@ -1,6 +1,11 @@ -*- coding: utf-8 -*- Changes with Apache 2.2.6 + *) mod_autoindex: Add in Type and Charset options to IndexOptions + directive. This allows the admin to explicitly set the + content-type and charset of the generated page. + [Jim Jagielski] + *) log core: ensure we use a special pool for stderr logging, so that the stderr channel remains valid from the time plog is destroyed, until the time the open_logs hook is called again. [William Rowe] diff --git a/docs/manual/mod/mod_autoindex.xml b/docs/manual/mod/mod_autoindex.xml index 47282615589..a3b568db74c 100644 --- a/docs/manual/mod/mod_autoindex.xml +++ b/docs/manual/mod/mod_autoindex.xml @@ -525,6 +525,36 @@ indexing of

+
Charset=character-set (Apache 2.0.61 and + later)
+ +
The Charset keyword allows you to + specify the character set of the generated page. The + default is either ISO-8859-1 or UTF-8, + depending on whether the underlying file system is unicode + or not. + + Example: + IndexOptions Charset=UTF-8 + +
+ +
Type=MIME content-type (Apache 2.0.61 and + later)
+ +
The Type keyword allows you to + specify the MIME content-type of the generated page. The default + is text/html. + + Example: + IndexOptions Type=text/plain + +
+
DescriptionWidth=[n | *] (Apache 2.0.23 and diff --git a/modules/generators/mod_autoindex.c b/modules/generators/mod_autoindex.c index 363ead1ab9d..8d514021a5b 100644 --- a/modules/generators/mod_autoindex.c +++ b/modules/generators/mod_autoindex.c @@ -138,6 +138,8 @@ typedef struct autoindex_config_struct { apr_array_header_t *hdr_list; apr_array_header_t *rdme_list; + char *ctype; + char *charset; } autoindex_config_rec; static char c_by_encoding, c_by_type, c_by_path; @@ -476,6 +478,12 @@ static const char *add_opts(cmd_parms *cmd, void *d, int argc, char *const argv[ d_cfg->desc_adjust = K_NOADJUST; } } + else if (!strncasecmp(w, "Type=", 5)) { + d_cfg->ctype = apr_pstrdup(cmd->pool, &w[5]); + } + else if (!strncasecmp(w, "Charset=", 8)) { + d_cfg->charset = apr_pstrdup(cmd->pool, &w[8]); + } else { return "Invalid directory indexing option"; } @@ -620,6 +628,9 @@ static void *merge_autoindex_configs(apr_pool_t *p, void *basev, void *addv) new->icon_height = add->icon_height ? add->icon_height : base->icon_height; new->icon_width = add->icon_width ? add->icon_width : base->icon_width; + new->ctype = add->ctype ? add->ctype : base->ctype; + new->charset = add->charset ? add->charset : base->charset; + new->alt_list = apr_array_append(p, add->alt_list, base->alt_list); new->ign_list = apr_array_append(p, add->ign_list, base->ign_list); new->hdr_list = apr_array_append(p, add->hdr_list, base->hdr_list); @@ -1971,6 +1982,8 @@ static int index_directory(request_rec *r, char *colargs; char *fullpath; apr_size_t dirpathlen; + char *ctype = "text/html"; + char *charset; if ((status = apr_dir_open(&thedir, name, r->pool)) != APR_SUCCESS) { ap_log_rerror(APLOG_MARK, APLOG_ERR, status, r, @@ -1978,11 +1991,27 @@ static int index_directory(request_rec *r, return HTTP_FORBIDDEN; } + if (autoindex_conf->ctype) { + ctype = autoindex_conf->ctype; + } + if (autoindex_conf->charset) { + charset = autoindex_conf->charset; + } + else { #if APR_HAS_UNICODE_FS - ap_set_content_type(r, "text/html;charset=utf-8"); + charset = "UTF-8"; #else - ap_set_content_type(r, "text/html"); + charset = "ISO-8859-1"; #endif + } + if (*charset) { + ap_set_content_type(r, apr_pstrcat(r->pool, ctype, ";charset=", + charset, NULL)); + } + else { + ap_set_content_type(r, ctype); + } + if (autoindex_opts & TRACK_MODIFIED) { ap_update_mtime(r, r->finfo.mtime); ap_set_last_modified(r);