mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-02-09 15:27:11 +00:00
lib/httpserver: fix compression for static files
This commit is contained in:
parent
99b634e0f9
commit
64bec11c91
1 changed files with 8 additions and 8 deletions
|
@ -299,22 +299,27 @@ type gzipResponseWriter struct {
|
|||
func (zrw *gzipResponseWriter) Write(p []byte) (int, error) {
|
||||
if !zrw.firstWriteDone {
|
||||
h := zrw.Header()
|
||||
if zrw.statusCode == http.StatusNoContent {
|
||||
zrw.disableCompression = true
|
||||
}
|
||||
if h.Get("Content-Encoding") != "" {
|
||||
zrw.disableCompression = true
|
||||
}
|
||||
if !zrw.disableCompression {
|
||||
h.Set("Content-Encoding", "gzip")
|
||||
h.Del("Content-Length")
|
||||
if h.Get("Content-Type") == "" {
|
||||
// Disable auto-detection of content-type, since it
|
||||
// is incorrectly detected after the compression.
|
||||
h.Set("Content-Type", "text/html")
|
||||
}
|
||||
}
|
||||
if zrw.statusCode == 0 {
|
||||
zrw.statusCode = http.StatusOK
|
||||
}
|
||||
zrw.ResponseWriter.WriteHeader(zrw.statusCode)
|
||||
zrw.firstWriteDone = true
|
||||
}
|
||||
if zrw.statusCode == 0 {
|
||||
zrw.WriteHeader(http.StatusOK)
|
||||
}
|
||||
if zrw.disableCompression {
|
||||
return zrw.ResponseWriter.Write(p)
|
||||
}
|
||||
|
@ -325,10 +330,6 @@ func (zrw *gzipResponseWriter) WriteHeader(statusCode int) {
|
|||
if zrw.statusCode != 0 {
|
||||
return
|
||||
}
|
||||
if statusCode == http.StatusNoContent {
|
||||
DisableResponseCompression(zrw.ResponseWriter)
|
||||
}
|
||||
zrw.ResponseWriter.WriteHeader(statusCode)
|
||||
zrw.statusCode = statusCode
|
||||
}
|
||||
|
||||
|
@ -347,7 +348,6 @@ func (zrw *gzipResponseWriter) Flush() {
|
|||
|
||||
func (zrw *gzipResponseWriter) Close() error {
|
||||
if !zrw.firstWriteDone {
|
||||
zrw.Header().Del("Content-Encoding")
|
||||
return nil
|
||||
}
|
||||
zrw.Flush()
|
||||
|
|
Loading…
Reference in a new issue