diff options
author | Runxi Yu <me@runxiyu.org> | 2025-03-15 17:36:09 +0800 |
---|---|---|
committer | Runxi Yu <me@runxiyu.org> | 2025-03-15 17:36:09 +0800 |
commit | 76f18a65d3f36431ca8e83c1fb62f5f326b188fd (patch) | |
tree | 60cb04ec7df7448c6c7ddefd015e073c9019c8f0 | |
parent | Serve static files (diff) | |
download | forge-76f18a65d3f36431ca8e83c1fb62f5f326b188fd.tar.gz forge-76f18a65d3f36431ca8e83c1fb62f5f326b188fd.tar.zst forge-76f18a65d3f36431ca8e83c1fb62f5f326b188fd.zip |
Detect static mime type instead of assuming everything's CSS
-rw-r--r-- | req.ha | 12 |
1 files changed, 11 insertions, 1 deletions
@@ -5,6 +5,7 @@ use fmt; use fs; use htmpl; use io; +use mime; use net::http; use net::uri; use strconv; @@ -73,7 +74,16 @@ fn handlereq(conn: io::handle, request: *http::request) (void | io::error | nome }; defer io::close(file)!; - start_response(conn, 200, "text/css")?; + fmt::println(fs_segments[len(fs_segments) - 1])!; + + let ext = strings::rcut(fs_segments[len(fs_segments) - 1], ".").1; + + let mimetype = match (mime::lookup_ext(ext)) { + case let m: *mime::mimetype => yield m.mime; + case null => yield "application/octet-stream"; + }; + + start_response(conn, 200, mimetype)?; io::copy(conn, file)?; case => |