fix: incorrect content-type of apk files (close #5385)

pull/5503/head
Andy Hsu 2023-11-06 18:20:25 +08:00
parent da1c7a4c23
commit 4355dae491
2 changed files with 8 additions and 0 deletions

View File

@ -163,8 +163,15 @@ func GetObjType(filename string, isDir bool) int {
return GetFileType(filename)
}
var extraMimeTypes = map[string]string{
".apk": "application/vnd.android.package-archive",
}
func GetMimeType(name string) string {
ext := path.Ext(name)
if m, ok := extraMimeTypes[ext]; ok {
return m
}
m := mime.TypeByExtension(ext)
if m != "" {
return m

View File

@ -76,4 +76,5 @@ func Proxy(w http.ResponseWriter, r *http.Request, link *model.Link, file model.
func attachFileName(w http.ResponseWriter, file model.Obj) {
fileName := file.GetName()
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"; filename*=UTF-8''%s`, fileName, url.PathEscape(fileName)))
w.Header().Set("Content-Type", utils.GetMimeType(fileName))
}