mirror of
https://github.com/VictoriaMetrics/VictoriaMetrics.git
synced 2025-03-21 15:45:01 +00:00
lib/httpserver: properly set status code for empty response
This commit is contained in:
parent
947009f459
commit
f5a4731412
1 changed files with 9 additions and 7 deletions
|
@ -365,10 +365,7 @@ func (zrw *gzipResponseWriter) Write(p []byte) (int, error) {
|
||||||
h.Set("Content-Type", "text/html")
|
h.Set("Content-Type", "text/html")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if zrw.statusCode == 0 {
|
zrw.writeHeader()
|
||||||
zrw.statusCode = http.StatusOK
|
|
||||||
}
|
|
||||||
zrw.ResponseWriter.WriteHeader(zrw.statusCode)
|
|
||||||
zrw.firstWriteDone = true
|
zrw.firstWriteDone = true
|
||||||
}
|
}
|
||||||
if zrw.disableCompression {
|
if zrw.disableCompression {
|
||||||
|
@ -378,12 +375,16 @@ func (zrw *gzipResponseWriter) Write(p []byte) (int, error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (zrw *gzipResponseWriter) WriteHeader(statusCode int) {
|
func (zrw *gzipResponseWriter) WriteHeader(statusCode int) {
|
||||||
if zrw.statusCode != 0 {
|
|
||||||
return
|
|
||||||
}
|
|
||||||
zrw.statusCode = statusCode
|
zrw.statusCode = statusCode
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (zrw *gzipResponseWriter) writeHeader() {
|
||||||
|
if zrw.statusCode == 0 {
|
||||||
|
zrw.statusCode = http.StatusOK
|
||||||
|
}
|
||||||
|
zrw.ResponseWriter.WriteHeader(zrw.statusCode)
|
||||||
|
}
|
||||||
|
|
||||||
// Implements http.Flusher
|
// Implements http.Flusher
|
||||||
func (zrw *gzipResponseWriter) Flush() {
|
func (zrw *gzipResponseWriter) Flush() {
|
||||||
if err := zrw.bw.Flush(); err != nil && !isTrivialNetworkError(err) {
|
if err := zrw.bw.Flush(); err != nil && !isTrivialNetworkError(err) {
|
||||||
|
@ -399,6 +400,7 @@ func (zrw *gzipResponseWriter) Flush() {
|
||||||
|
|
||||||
func (zrw *gzipResponseWriter) Close() error {
|
func (zrw *gzipResponseWriter) Close() error {
|
||||||
if !zrw.firstWriteDone {
|
if !zrw.firstWriteDone {
|
||||||
|
zrw.writeHeader()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
zrw.Flush()
|
zrw.Flush()
|
||||||
|
|
Loading…
Reference in a new issue