mirror of
https://github.com/octoleo/syncthing.git
synced 2025-02-08 23:08:27 +00:00
Don't trust mime.TypeByExtension for the easy stuff (fixes #598)
This commit is contained in:
parent
3c67c06654
commit
5915e8e86a
@ -680,7 +680,7 @@ func embeddedStatic(assetDir string) http.Handler {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
mtype := mime.TypeByExtension(filepath.Ext(r.URL.Path))
|
mtype := mimeTypeForFile(file)
|
||||||
if len(mtype) != 0 {
|
if len(mtype) != 0 {
|
||||||
w.Header().Set("Content-Type", mtype)
|
w.Header().Set("Content-Type", mtype)
|
||||||
}
|
}
|
||||||
@ -690,3 +690,26 @@ func embeddedStatic(assetDir string) http.Handler {
|
|||||||
w.Write(bs)
|
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)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user