[MM-63578] Fix support packet caching issue (#31133)
Fix support packet caching issue by adding no-cache headers Added Cache-Control headers to prevent browser caching when downloading support packets. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
2fd319b0ac
Коммит
0cf6361139
@@ -54,20 +54,23 @@ func WriteFileResponse(filename string, contentType string, contentSize int64, l
|
||||
http.ServeContent(w, r, filename, lastModification, fileReader)
|
||||
}
|
||||
|
||||
// WriteStreamResponse copies the ReadCloser `r` to the ResponseWriter `w`. Use this when you need to stream a response
|
||||
// WriteStreamResponse copies the Reader `r` to the ResponseWriter `w`. Use this when you need to stream a response
|
||||
// to the client that will appear as a file `filename` of type `contentType`.
|
||||
func WriteStreamResponse(w http.ResponseWriter, r io.ReadCloser, filename string, contentType string, forceDownload bool) error {
|
||||
func WriteStreamResponse(w http.ResponseWriter, r io.Reader, filename string, contentType string, forceDownload bool) error {
|
||||
setHeaders(w, contentType, forceDownload, filename)
|
||||
|
||||
if _, err := io.Copy(w, r); err != nil {
|
||||
return errors.Wrap(err, "error streaming ReadCloser")
|
||||
return errors.Wrap(err, "error streaming Reader")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func setHeaders(w http.ResponseWriter, contentType string, forceDownload bool, filename string) {
|
||||
w.Header().Set("Cache-Control", "private, max-age=86400")
|
||||
// Only set Cache-Control if it hasn't been set already
|
||||
if w.Header().Get("Cache-Control") == "" {
|
||||
w.Header().Set("Cache-Control", "private, max-age=86400")
|
||||
}
|
||||
w.Header().Set("X-Content-Type-Options", "nosniff")
|
||||
|
||||
if contentType == "" {
|
||||
|
||||
Ссылка в новой задаче
Block a user