mirror of
https://github.com/prometheus/prometheus.git
synced 2024-11-12 00:24:04 -08:00
b5c833ca21
* Update go.mod dependencies before release Signed-off-by: Julius Volz <julius.volz@gmail.com> * Add issue for showing query warnings in promtool Signed-off-by: Julius Volz <julius.volz@gmail.com> * Revert json-iterator back to 1.1.6 It produced errors when marshaling Point values with special float values. Signed-off-by: Julius Volz <julius.volz@gmail.com> * Fix expected step values in promtool tests after client_golang update Signed-off-by: Julius Volz <julius.volz@gmail.com> * Update generated protobuf code after proto dep updates Signed-off-by: Julius Volz <julius.volz@gmail.com>
146 lines
3 KiB
Go
146 lines
3 KiB
Go
// +build go1.7,!go1.8
|
|
|
|
package nethttp
|
|
|
|
import (
|
|
"io"
|
|
"net/http"
|
|
)
|
|
|
|
type statusCodeTracker struct {
|
|
http.ResponseWriter
|
|
status int
|
|
wroteheader bool
|
|
}
|
|
|
|
func (w *statusCodeTracker) WriteHeader(status int) {
|
|
w.status = status
|
|
w.wroteheader = true
|
|
w.ResponseWriter.WriteHeader(status)
|
|
}
|
|
|
|
func (w *statusCodeTracker) Write(b []byte) (int, error) {
|
|
if !w.wroteheader {
|
|
w.wroteheader = true
|
|
w.status = 200
|
|
}
|
|
return w.ResponseWriter.Write(b)
|
|
}
|
|
|
|
// wrappedResponseWriter returns a wrapped version of the original
|
|
// ResponseWriter and only implements the same combination of additional
|
|
// interfaces as the original. This implementation is based on
|
|
// https://github.com/felixge/httpsnoop.
|
|
func (w *statusCodeTracker) wrappedResponseWriter() http.ResponseWriter {
|
|
var (
|
|
hj, i0 = w.ResponseWriter.(http.Hijacker)
|
|
cn, i1 = w.ResponseWriter.(http.CloseNotifier)
|
|
fl, i3 = w.ResponseWriter.(http.Flusher)
|
|
rf, i4 = w.ResponseWriter.(io.ReaderFrom)
|
|
)
|
|
i2 := false
|
|
|
|
switch {
|
|
case !i0 && !i1 && !i2 && !i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
}{w}
|
|
case !i0 && !i1 && !i2 && !i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
io.ReaderFrom
|
|
}{w, rf}
|
|
case !i0 && !i1 && !i2 && i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Flusher
|
|
}{w, fl}
|
|
case !i0 && !i1 && !i2 && i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Flusher
|
|
io.ReaderFrom
|
|
}{w, fl, rf}
|
|
case !i0 && i1 && !i2 && !i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.CloseNotifier
|
|
}{w, cn}
|
|
case !i0 && i1 && !i2 && !i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.CloseNotifier
|
|
io.ReaderFrom
|
|
}{w, cn, rf}
|
|
case !i0 && i1 && !i2 && i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.CloseNotifier
|
|
http.Flusher
|
|
}{w, cn, fl}
|
|
case !i0 && i1 && !i2 && i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.CloseNotifier
|
|
http.Flusher
|
|
io.ReaderFrom
|
|
}{w, cn, fl, rf}
|
|
case i0 && !i1 && !i2 && !i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
}{w, hj}
|
|
case i0 && !i1 && !i2 && !i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
io.ReaderFrom
|
|
}{w, hj, rf}
|
|
case i0 && !i1 && !i2 && i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.Flusher
|
|
}{w, hj, fl}
|
|
case i0 && !i1 && !i2 && i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.Flusher
|
|
io.ReaderFrom
|
|
}{w, hj, fl, rf}
|
|
case i0 && i1 && !i2 && !i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.CloseNotifier
|
|
}{w, hj, cn}
|
|
case i0 && i1 && !i2 && !i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.CloseNotifier
|
|
io.ReaderFrom
|
|
}{w, hj, cn, rf}
|
|
case i0 && i1 && !i2 && i3 && !i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.CloseNotifier
|
|
http.Flusher
|
|
}{w, hj, cn, fl}
|
|
case i0 && i1 && !i2 && i3 && i4:
|
|
return struct {
|
|
http.ResponseWriter
|
|
http.Hijacker
|
|
http.CloseNotifier
|
|
http.Flusher
|
|
io.ReaderFrom
|
|
}{w, hj, cn, fl, rf}
|
|
default:
|
|
return struct {
|
|
http.ResponseWriter
|
|
}{w}
|
|
}
|
|
}
|