This fixes the following error when using WebSockets with access logs
enabled:
http: proxy error: can't switch protocols using non-Hijacker ResponseWriter type *main.interceptRW
We also add a Hijack method for upcoming (Go 1.20) ResponseController
support.
---
interceptor.go | 20 ++++++++++++++++++++
1 file changed, 20 insertions(+)
diff --git a/interceptor.go b/interceptor.go
index 6e2fdbb..17aa1ad 100644
--- a/interceptor.go+++ b/interceptor.go
@@ -1,6 +1,9 @@
package main
import (
+ "bufio"+ "fmt"+ "net" "net/http"
)
@@ -10,6 +13,23 @@ type interceptRW struct {
size int
}
+func (w *interceptRW) Unwrap() http.ResponseWriter {+ return w.ResponseWriter+}++func (w *interceptRW) Flush() {+ if f, ok := w.ResponseWriter.(http.Flusher); ok {+ f.Flush()+ }+}++func (w *interceptRW) Hijack() (net.Conn, *bufio.ReadWriter, error) {+ if h, ok := w.ResponseWriter.(http.Hijacker); ok {+ return h.Hijack()+ }+ return nil, nil, fmt.Errorf("connection does not support hijacking")+}+func (w *interceptRW) WriteHeader(status int) {
w.status = status
w.ResponseWriter.WriteHeader(status)
base-commit: b5c6ce57dba6a7a4b37a7baba7bb1b21c4debe69
--
2.39.1