Makefile,internal: fix websocket regression and other small things (#830)

- fix websocket regression and add test to prevent in the future
- fix staticheck errors
- remove proxy package remnants from Makefile 

fix #829
This commit is contained in:
Benson Wong
2026-06-09 21:37:53 -07:00
committed by GitHub
parent 44e1501e81
commit 0cfe5a6639
7 changed files with 200 additions and 21 deletions
+17
View File
@@ -1,12 +1,14 @@
package server
import (
"bufio"
"bytes"
"compress/flate"
"compress/gzip"
"encoding/json"
"fmt"
"io"
"net"
"net/http"
"strings"
"sync"
@@ -427,6 +429,12 @@ func (w *responseBodyCopier) Write(b []byte) (int, error) {
if !w.wroteHeader {
w.WriteHeader(http.StatusOK)
}
// On a protocol upgrade (e.g. websocket) the body is raw framed data, not a
// metrics-parseable response, so write straight to the client without
// buffering a copy we can't use.
if w.status == http.StatusSwitchingProtocols {
return w.ResponseWriter.Write(b)
}
return w.tee.Write(b)
}
@@ -446,5 +454,14 @@ func (w *responseBodyCopier) Flush() {
}
}
// Hijack forwards to the underlying writer so httputil.ReverseProxy can take
// over the connection for websocket upgrades.
func (w *responseBodyCopier) Hijack() (net.Conn, *bufio.ReadWriter, error) {
if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
return hj.Hijack()
}
return nil, nil, fmt.Errorf("underlying ResponseWriter does not support hijacking")
}
func (w *responseBodyCopier) Status() int { return w.status }
func (w *responseBodyCopier) StartTime() time.Time { return w.start }