diff --git a/api/metrics.go b/api/metrics.go index a7fafbf0f..ac52fc071 100644 --- a/api/metrics.go +++ b/api/metrics.go @@ -6,6 +6,9 @@ package api import ( + "bufio" + "errors" + "net" "net/http" "strconv" "time" @@ -34,6 +37,21 @@ func (m *metricsResponseWriter) WriteHeader(code int) { m.ResponseWriter.WriteHeader(code) } +// Hijack complies the writer with WS subscriptions interface +// Hijack lets the caller take over the connection. +// After a call to Hijack the HTTP server library +// will not do anything else with the connection. +// +// It becomes the caller's responsibility to manage +// and close the connection. +func (m *metricsResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + h, ok := m.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("hijack not supported") + } + return h.Hijack() +} + // metricsMiddleware is a middleware that records metrics for each request. func metricsMiddleware(next http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {