修复附件下载响应长度
Some checks are pending
Security Checks / security (push) Waiting to run

This commit is contained in:
smail 2026-10-04 12:15:38 +08:00
parent 10b0470612
commit 09c8ae421a

View File

@ -10,6 +10,7 @@ import (
"github.com/spf13/cast" "github.com/spf13/cast"
"net/http" "net/http"
"net/url" "net/url"
"strconv"
"strings" "strings"
"unicode" "unicode"
) )
@ -50,6 +51,7 @@ func Download(ctx *context.Context, w http.ResponseWriter, req *http.Request) {
} }
fileName = safeDownloadName(fileName) fileName = safeDownloadName(fileName)
w.Header().Set("Content-Type", "application/octet-stream") w.Header().Set("Content-Type", "application/octet-stream")
w.Header().Set("Content-Length", strconv.Itoa(len(content)))
w.Header().Set("X-Content-Type-Options", "nosniff") w.Header().Set("X-Content-Type-Options", "nosniff")
w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"attachment\"; filename*=UTF-8''%s", url.PathEscape(fileName))) w.Header().Set("Content-Disposition", fmt.Sprintf("attachment; filename=\"attachment\"; filename*=UTF-8''%s", url.PathEscape(fileName)))
if _, err := w.Write(content); err != nil { if _, err := w.Write(content); err != nil {