Fix header writing

This commit is contained in:
Mukhtar Akere
2025-03-22 00:30:00 +01:00
parent 738474be16
commit 49875446b4
2 changed files with 6 additions and 2 deletions

View File

@@ -94,6 +94,7 @@
"discord_webhook_url": "https://discord.com/api/webhooks/...",
"webdav": {
"torrents_refresh_interval": "5m",
"download_links_refresh_interval": "1h"
"download_links_refresh_interval": "1h",
"rc_url": "http://192.168.0.219:9990"
}
}

View File

@@ -289,15 +289,16 @@ func (h *Handler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
for k, v := range responseRecorder.Header() {
w.Header()[k] = v
}
w.WriteHeader(responseRecorder.Code)
if acceptsGzip(r) {
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(gzippedData)))
w.WriteHeader(responseRecorder.Code)
w.Write(gzippedData)
} else {
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(responseData)))
w.WriteHeader(responseRecorder.Code)
w.Write(responseData)
}
return
@@ -416,9 +417,11 @@ func (h *Handler) serveFromCacheIfValid(w http.ResponseWriter, r *http.Request,
w.Header().Set("Content-Encoding", "gzip")
w.Header().Set("Vary", "Accept-Encoding")
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(respCache.GzippedData)))
w.WriteHeader(http.StatusOK)
w.Write(respCache.GzippedData)
} else {
w.Header().Set("Content-Length", fmt.Sprintf("%d", len(respCache.Data)))
w.WriteHeader(http.StatusOK)
w.Write(respCache.Data)
}
return true