Use proper content-type for downloads to avoid Chrome insecure download block
This commit is contained in:
parent
a1d156bbd5
commit
9d6ad09b53
6
main.go
6
main.go
|
|
@ -299,7 +299,11 @@ func servePDF(w http.ResponseWriter, r *http.Request) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
defer f.Close()
|
defer f.Close()
|
||||||
w.Header().Set("Content-Type", "application/octet-stream")
|
if ext == ".pdf" || ext == "" {
|
||||||
|
w.Header().Set("Content-Type", "application/pdf")
|
||||||
|
} else {
|
||||||
|
w.Header().Set("Content-Type", "text/plain")
|
||||||
|
}
|
||||||
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
w.Header().Set("Content-Disposition", fmt.Sprintf(`attachment; filename="%s"`, filename))
|
||||||
w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
|
w.Header().Set("Content-Length", fmt.Sprintf("%d", fi.Size()))
|
||||||
io.Copy(w, f)
|
io.Copy(w, f)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue