diff options
author | bptato <nincsnevem662@gmail.com> | 2024-03-16 20:11:53 +0100 |
---|---|---|
committer | bptato <nincsnevem662@gmail.com> | 2024-03-16 20:17:01 +0100 |
commit | 9aa8e20bd5552916c6b382659224f1003b02dbc7 (patch) | |
tree | 95c39447d43e14a8435a25f83ecd76a012a94678 | |
parent | 5b330ef56e50ad454712a77f805377b41dfb140b (diff) | |
download | chawan-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.)
-rw-r--r-- | src/local/container.nim | 3 | ||||
-rw-r--r-- | src/utils/mimeguess.nim | 5 |
2 files changed, 5 insertions, 3 deletions
diff --git a/src/local/container.nim b/src/local/container.nim index 011c7279..62799c56 100644 --- a/src/local/container.nim +++ b/src/local/container.nim @@ -1412,7 +1412,8 @@ proc applyResponse*(container: Container; response: Response; if container.contentType.isNone: var contentType = response.getContentType() if contentType == "application/octet-stream": - contentType = mimeTypes.guessContentType(container.url.pathname) + contentType = mimeTypes.guessContentType(container.url.pathname, + "text/plain") container.contentType = some(contentType) # setup charsets: # * override charset 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", |