fix(files): encode download filenames (#91)

Co-authored-by: rissrice2105-agent <rissrice2105-agent@users.noreply.github.com>
This commit is contained in:
RissRIce 2026-07-14 00:54:18 -06:00 committed by GitHub
parent 21630c2d17
commit b777bd72e8
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 42 additions and 1 deletions

View file

@ -7,6 +7,7 @@ import (
"fmt"
"html/template"
"io"
"mime"
"net/http"
"os"
"path"
@ -224,7 +225,9 @@ func (h *webSrv) handleDownload(w http.ResponseWriter, r *http.Request) {
return
}
defer f.Close()
w.Header().Set("Content-Disposition", "attachment; filename=\""+path.Base(vpath)+"\"")
w.Header().Set("Content-Disposition", mime.FormatMediaType("attachment", map[string]string{
"filename": path.Base(vpath),
}))
w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.FormatInt(fi.Size(), 10))
_, _ = io.Copy(w, f)