hi all
it's come up a few times for me (and other users) that string-type
ErrorDocuments and custom responses default to "text/html". however, lots
of people are using servers for xml-only content and want to be able to set
custom responses to simple xml strings without the overhead of a full
internal redirect. for example, anyway.
here is one way around the issue (if you agree that it's an issue :). the
attached patch:
- adds a new ErrorDocumentType directive, for setting the mime type of
string custom responses and ErrorDocuments
- removes the hard-coded charset previously set for all string-based errors
- respects AddDefaultCharset settings for both default (still "text/html")
and ErrorDocumentType-set types.
so, the big change is that, by default, simple strings no longer have a
charset sent with them unless the server is specifically configured that
way. regardless of the rest of the patch, it seems this ought to be the
default behavior anyway, but I guess it hasn't been an issue in the past.
anyway, just an idea. comments or other suggestions appreciated.
--Geoff
Index: include/http_core.h
===================================================================
RCS file: /home/cvspublic/httpd-2.0/include/http_core.h,v
retrieving revision 1.77
diff -u -r1.77 http_core.h
--- include/http_core.h 1 Jan 2004 13:26:16 -0000 1.77
+++ include/http_core.h 3 Feb 2004 15:41:07 -0000
@@ -553,6 +553,12 @@
unsigned int enable_sendfile : 2; /* files in this dir can be mmap'ed */
unsigned int allow_encoded_slashes : 1; /* URLs may contain %2f w/o being
* pitched indiscriminately */
+
+ /* if the ErrorDocument or custom response is a plain string (not an
+ * internal or external redirect), the MIME type to use for the string
+ */
+ const char *error_type;
+
} core_dir_config;
/* Per-server core configuration */
Index: modules/http/http_protocol.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/modules/http/http_protocol.c,v
retrieving revision 1.476
diff -u -r1.476 http_protocol.c
--- modules/http/http_protocol.c 16 Jan 2004 20:11:12 -0000 1.476
+++ modules/http/http_protocol.c 3 Feb 2004 15:41:27 -0000
@@ -2334,8 +2334,14 @@
int status = r->status;
int idx = ap_index_of_response(status);
char *custom_response;
+ const char *error_type;
+ core_dir_config *dcfg;
const char *location = apr_table_get(r->headers_out, "Location");
+ dcfg = (core_dir_config *)ap_get_module_config(r->per_dir_config,
+ &core_module);
+
+
/* At this point, we are starting the response over, so we have to reset
* this value.
*/
@@ -2395,7 +2401,15 @@
r->content_languages = NULL;
r->content_encoding = NULL;
r->clength = 0;
- ap_set_content_type(r, "text/html; charset=iso-8859-1");
+
+ if (dcfg->error_type == NULL) {
+ error_type = ap_make_content_type(r, "text/html");
+ }
+ else {
+ /* ErrorDocumentType */
+ error_type = ap_make_content_type(r, dcfg->error_type);
+ }
+ ap_set_content_type(r, error_type);
if ((status == HTTP_METHOD_NOT_ALLOWED)
|| (status == HTTP_NOT_IMPLEMENTED)) {
Index: server/core.c
===================================================================
RCS file: /home/cvspublic/httpd-2.0/server/core.c,v
retrieving revision 1.257
diff -u -r1.257 core.c
--- server/core.c 25 Jan 2004 22:03:38 -0000 1.257
+++ server/core.c 3 Feb 2004 15:41:44 -0000
@@ -182,6 +182,8 @@
conf->enable_sendfile = ENABLE_SENDFILE_UNSET;
conf->allow_encoded_slashes = 0;
+ conf->error_type = NULL;
+
return (void *)conf;
}
@@ -449,6 +451,10 @@
conf->allow_encoded_slashes = new->allow_encoded_slashes;
+ if (new->error_type) {
+ conf->error_type = new->error_type;
+ }
+
return (void*)conf;
}
@@ -3121,6 +3127,9 @@
AP_INIT_TAKE1("DocumentRoot", set_document_root, NULL, RSRC_CONF,
"Root directory of the document tree"),
AP_INIT_TAKE2("ErrorDocument", set_error_document, NULL, OR_FILEINFO,
+ "Change responses for HTTP errors"),
+AP_INIT_TAKE1("ErrorDocumentType", ap_set_string_slot_lower,
+ (void *)APR_OFFSETOF(core_dir_config, error_type), OR_FILEINFO,
"Change responses for HTTP errors"),
AP_INIT_RAW_ARGS("AllowOverride", set_override, NULL, ACCESS_CONF,
"Controls what groups of directives can be configured by per-directory "