diff options
author | Jakob Borg <jakob@nym.se> | 2014-09-04 08:24:42 +0200 |
---|---|---|
committer | Jakob Borg <jakob@nym.se> | 2014-09-04 08:26:12 +0200 |
commit | 5915e8e86ada284d9e55b5a8b91de11a36f90b88 (patch) | |
tree | 62c5cb880f0548c23d50a939acf2fb8365fcf4af | |
parent | 3c67c0665441cb2f4ed1699aefeead012a7a07a2 (diff) | |
download | syncthing-5915e8e86ada284d9e55b5a8b91de11a36f90b88.tar.gz syncthing-5915e8e86ada284d9e55b5a8b91de11a36f90b88.zip |
Don't trust mime.TypeByExtension for the easy stuff (fixes #598)
-rw-r--r-- | cmd/syncthing/gui.go | 25 |
1 files changed, 24 insertions, 1 deletions
diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 0a01b920b..0f9a1cd65 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -680,7 +680,7 @@ func embeddedStatic(assetDir string) http.Handler { return } - mtype := mime.TypeByExtension(filepath.Ext(r.URL.Path)) + mtype := mimeTypeForFile(file) if len(mtype) != 0 { w.Header().Set("Content-Type", mtype) } @@ -690,3 +690,26 @@ func embeddedStatic(assetDir string) http.Handler { w.Write(bs) }) } + +func mimeTypeForFile(file string) string { + // We use a built in table of the common types since the system + // TypeByExtension might be unreliable. But if we don't know, we delegate + // to the system. + ext := filepath.Ext(file) + switch ext { + case ".htm", ".html": + return "text/html" + case ".css": + return "text/css" + case ".js": + return "application/javascript" + case ".json": + return "application/json" + case ".png": + return "image/png" + case ".ttf": + return "application/x-font-ttf" + default: + return mime.TypeByExtension(ext) + } +} |