httpd-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Rodent of Unusual Size <Ken.C...@Golux.Com>
Subject [PATCH] PR#4524 and bare content-types
Date Thu, 03 Jun 1999 22:17:06 GMT
PR#4524 points out an interesting fact: mod_autoindex looks for an
*exact* match on the content-type against "text/html".  This
doesn't work well when someone has labelled all HTML documents
with something like

AddType "text/html;charset=foo" .html

mod_autoindex is almost certainly not the only offender, either.
But I'm not going to look for the others right now.

This patch is a 1.3 workaround; it adds a routine that returns
the base content-type minus any trailing parameters or whitespace.
Actually, it works with any HTTP field value that uses a
production like '*( ";" param)'.

For 2.0 we might want to consider breaking r->content_type into
r->content_type and (table *)r->content_params.
-- 
#ken    P-)}

Ken Coar                    <http://Web.Golux.Com/coar/>
Apache Software Foundation  <http://www.apache.org/>
"Apache Server for Dummies" <http://Web.Golux.Com/coar/ASFD/>

Index: include/httpd.h
===================================================================
RCS file: /home/cvs/apache-1.3/src/include/httpd.h,v
retrieving revision 1.279
diff -u -r1.279 httpd.h
--- httpd.h	1999/06/02 07:08:18	1.279
+++ httpd.h	1999/06/03 21:59:49
@@ -920,6 +920,7 @@
 
 API_EXPORT(struct tm *) ap_get_gmtoff(int *tz);
 API_EXPORT(char *) ap_get_time(void);
+API_EXPORT(char *) ap_field_noparm(pool *p, const char *intype);
 API_EXPORT(char *) ap_ht_time(pool *p, time_t t, const char *fmt, int gmt);
 API_EXPORT(char *) ap_gm_timestr_822(pool *p, time_t t);
 
Index: main/util.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/main/util.c,v
retrieving revision 1.162
diff -u -r1.162 util.c
--- util.c	1999/05/25 15:24:01	1.162
+++ util.c	1999/06/03 21:59:57
@@ -119,6 +119,26 @@
     return (time_string);
 }
 
+/*
+ * Examine a field value (such as a media-/content-type) string and return
+ * it sans any parameters; e.g., strip off any ';charset=foo' and the like.
+ */
+API_EXPORT(char *) ap_field_noparm(pool *p, const char *intype)
+{
+    char *type;
+    const char *line;
+    char *work;
+
+    line = intype;
+    type = ap_getword(p, &line, ';');
+    work = &type[strlen(type)];
+    while ((work >= type) && (ap_isspace(*work) || (*work == '\0'))) {
+	work--;
+    }
+    *++work = '\0';
+    return type;
+}
+
 API_EXPORT(char *) ap_ht_time(pool *p, time_t t, const char *fmt, int gmt)
 {
     char ts[MAX_STRING_LEN];
Index: modules/standard/mod_autoindex.c
===================================================================
RCS file: /home/cvs/apache-1.3/src/modules/standard/mod_autoindex.c,v
retrieving revision 1.108
diff -u -r1.108 mod_autoindex.c
--- mod_autoindex.c	1999/05/13 19:00:43	1.108
+++ mod_autoindex.c	1999/06/03 21:59:57
@@ -957,7 +957,8 @@
 	 * SSIs.
 	 */
 	if (rr->content_type != NULL) {
-	    if (!strcasecmp("text/html", rr->content_type)) {
+	    if (!strcasecmp(ap_field_noparm(r->pool, rr->content_type),
+			    "text/html")) {
 		/* Hope everything will work... */
 		emit_amble = 0;
 		emit_H1 = 0;
@@ -1038,7 +1039,8 @@
 	 * SSIs.
 	 */
 	if (rr->content_type != NULL) {
-	    if (!strcasecmp("text/html", rr->content_type)) {
+	    if (!strcasecmp(ap_field_noparm(r->pool, rr->content_type),
+			    "text/html")) {
 		if (ap_run_sub_req(rr) == OK) {
 		    /* worked... */
 		    suppress_sig = 1;
@@ -1079,8 +1081,8 @@
     if (r->status != HTTP_OK) {
 	return NULL;
     }
-    if (r->content_type
-	&& (!strcmp(r->content_type, "text/html")
+    if ((r->content_type != NULL)
+	&& (!strcasecmp(ap_field_noparm(r->pool, r->content_type), "text/html")
 	    || !strcmp(r->content_type, INCLUDES_MAGIC_TYPE))
 	&& !r->content_encoding) {
         if (!(thefile = ap_pfopen(r->pool, r->filename, "r"))) {


Mime
View raw message