tcp80 Content-Type headers overhaul
tcp80.org·182w
Preview
Report Post

be0ba 2022-07-02

diff --git a/tcp80.c b/tcp80.c
index ab3e56b..05af9f4 100644
--- a/tcp80.c
+++ b/tcp80.c
@@ -36,6 +36,7 @@ Ctype ctypemap[] = {
".html", "text/html;charset=utf-8",
".txt", "text/plain;charset=utf-8",
".md", "text/markdown;charset=utf-8",
+	".css", "text/css;charset=utf-8",
};

Pair*
@@ -228,8 +229,20 @@ headers(char *path, Dir *d)
f[0], tm->mday, f[1], f[5], f[3], f[4]);
}
isdir = d && (d->qid.type & QTDIR);
-	if(isdir || cistrstr(path, ".htm"))
+	if(isdir){
print("Content-Type: text/html; charset=utf-8\r\n");
+	}else{
+        int i;
+        for(i = 0; i < nelem(ctypemap); i++){
+            int offset = strlen(path) - strlen(ctypemap[i].suffix);
+            if (offset <= 0)
+                break;
+            if(cistrcmp(path+offset, ctypemap[i].suffix) == 0){
+		...

Similar Posts

Loading similar posts...