From 9237baaba7bcd7d60f56b815306917cb11159e89 Mon Sep 17 00:00:00 2001 From: Akshay Nanavare Date: Tue, 3 Sep 2024 12:58:30 +0530 Subject: [PATCH] add hijack function support to ResponseWriter struct --- go/httpmetrics/response_writer.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/go/httpmetrics/response_writer.go b/go/httpmetrics/response_writer.go index 034c521..3454b92 100644 --- a/go/httpmetrics/response_writer.go +++ b/go/httpmetrics/response_writer.go @@ -1,6 +1,8 @@ package httpmetrics import ( + "bufio" + "net" "net/http" "sync" ) @@ -31,6 +33,15 @@ func (rw *ResponseWriter) WriteHeader(statusCode int) { rw.w.WriteHeader(statusCode) } +func (rw *ResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + hj, ok := rw.w.(http.Hijacker) + if !ok { + return nil, nil, http.ErrNotSupported + } + + return hj.Hijack() +} + func (rw *ResponseWriter) Write(data []byte) (int, error) { // rw.w.WriteHeader(rw.code) if rw.code >= http.StatusInternalServerError {