Re: Content type

[email protected] (Paul Jarc) Wed, 10 Mar 2004 12:21:27 -0500
Newsgroups gmane.comp.djb.publicfile
Organization What did you have in mind? A short, blunt, human pyramid?
Message-ID <[email protected]>
[email protected] wrote:
> httpd does not support content-type.

Use Uwe's patch at publicfile.org.  Or, here's a patch of mine, based
on Uwe's.  (Mine adds a missing #include, and supports a $CT variable
to specify the default content type for unrecognized extensions.)


paul
publicfile-0.52-ct.patch (text/x-patch, 1.2 KB)
diff -ur publicfile-0.52-orig/filetype.c publicfile-0.52/filetype.c
--- publicfile-0.52-orig/filetype.c	1999-11-09 02:23:24.000000000 -0500
+++ publicfile-0.52/filetype.c	2004-02-02 17:55:47.000000000 -0500
@@ -1,5 +1,7 @@
 #include "filetype.h"
 #include "str.h"
+#include "env.h"
+#include "stralloc.h"
 
 void filetype(char *fn,stralloc *contenttype)
 {
@@ -22,7 +24,6 @@
       if (!stralloc_append(contenttype,&ch)) _exit(21);
     }
   else {
-    result = "text/plain";
     if (str_equal(x,".html")) result = "text/html";
     else if (str_equal(x,".gz")) result = "application/x-gzip";
     else if (str_equal(x,".dvi")) result = "application/x-dvi";
@@ -32,6 +33,16 @@
     else if (str_equal(x,".jpeg")) result = "image/jpeg";
     else if (str_equal(x,".png")) result = "image/png";
     else if (str_equal(x,".mpeg")) result = "video/mpeg";
+    else {
+      stralloc envname = {0};
+      if (!stralloc_copys(&envname,"CT_")) _exit(21);
+      if (!stralloc_cats(&envname,x+1)) _exit(21);
+      if (!stralloc_0(&envname)) _exit(21);
+      result = env_get(envname.s);
+      alloc_free(envname.s);
+      if (!result) result = env_get("CT");
+      if (!result) result = "text/plain";
+    }
 
     if (!stralloc_cats(contenttype,result)) _exit(21);
   }