about summary refs log tree commit diff stats
path: root/src/utils
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-03-16 20:11:53 +0100
committerbptato <nincsnevem662@gmail.com>2024-03-16 20:17:01 +0100
commit9aa8e20bd5552916c6b382659224f1003b02dbc7 (patch)
tree95c39447d43e14a8435a25f83ecd76a012a94678 /src/utils
parent5b330ef56e50ad454712a77f805377b41dfb140b (diff)
downloadchawan-9aa8e20bd5552916c6b382659224f1003b02dbc7.tar.gz
container: fall back to text/plain instead of application/octet-stream
This has its own problems, but application/octet-stream has the horrible
consequence that opening any local file with an unrecognized type
automatically quits the browser.

(FWIW, w3m also falls back to text/plain, so it's not such an unreasonable
default.)

The proper solution would be to a) fix the bug that makes the browser
auto-quit and b) show a "what to do" prompt for unrecognized file types
(and allow users to override it, preferably on a per-protocol basis.)
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/mimeguess.nim5
1 files changed, 3 insertions, 2 deletions
diff --git a/src/utils/mimeguess.nim b/src/utils/mimeguess.nim
index 4b8df086..f13eaf89 100644
--- a/src/utils/mimeguess.nim
+++ b/src/utils/mimeguess.nim
@@ -8,7 +8,8 @@ const DefaultGuess* = block:
   let ss = newStringStream(staticRead"res/mime.types")
   parseMimeTypes(ss)
 
-func guessContentType*(mimeTypes: MimeTypes; path: string): string =
+func guessContentType*(mimeTypes: MimeTypes; path: string;
+    fallback = "application/octet-stream"): string =
   var n = 0
   for i in countdown(path.high, 0):
     if path[i] == '/':
@@ -20,7 +21,7 @@ func guessContentType*(mimeTypes: MimeTypes; path: string): string =
     let ext = path.substr(n + 1)
     if ext in mimeTypes:
       return mimeTypes[ext]
-  return "application/octet-stream"
+  return fallback
 
 const JavaScriptTypes = [
   "application/ecmascript",