Skip to content

Commit 35ef65d

Browse files
authored
Merge pull request #634 from prometheus/beorn7/promhttp
Add WriteHeader call to Flush
2 parents 4efc3cc + ad58180 commit 35ef65d

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

prometheus/promhttp/delegator.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ func (r *responseWriterDelegator) WriteHeader(code int) {
6262
}
6363

6464
func (r *responseWriterDelegator) Write(b []byte) (int, error) {
65+
// If applicable, call WriteHeader here so that observeWriteHeader is
66+
// handled appropriately.
6567
if !r.wroteHeader {
6668
r.WriteHeader(http.StatusOK)
6769
}
@@ -82,12 +84,19 @@ func (d closeNotifierDelegator) CloseNotify() <-chan bool {
8284
return d.ResponseWriter.(http.CloseNotifier).CloseNotify()
8385
}
8486
func (d flusherDelegator) Flush() {
87+
// If applicable, call WriteHeader here so that observeWriteHeader is
88+
// handled appropriately.
89+
if !d.wroteHeader {
90+
d.WriteHeader(http.StatusOK)
91+
}
8592
d.ResponseWriter.(http.Flusher).Flush()
8693
}
8794
func (d hijackerDelegator) Hijack() (net.Conn, *bufio.ReadWriter, error) {
8895
return d.ResponseWriter.(http.Hijacker).Hijack()
8996
}
9097
func (d readerFromDelegator) ReadFrom(re io.Reader) (int64, error) {
98+
// If applicable, call WriteHeader here so that observeWriteHeader is
99+
// handled appropriately.
91100
if !d.wroteHeader {
92101
d.WriteHeader(http.StatusOK)
93102
}

0 commit comments

Comments
 (0)