From 6793e8ef1dd3e8ee65af0793dd09559259ca8425 Mon Sep 17 00:00:00 2001 From: Evan Chen Date: Fri, 19 Nov 2021 15:08:51 +0800 Subject: [PATCH] feat: add support for hijack --- guard.go | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/guard.go b/guard.go index db6fb4a..cfab627 100644 --- a/guard.go +++ b/guard.go @@ -1,7 +1,9 @@ package guard import ( + "bufio" "encoding/base64" + "errors" "fmt" "net" "net/http" @@ -33,6 +35,14 @@ type responseWriter struct { err string } +func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + h, ok := w.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("hijack not supported") + } + return h.Hijack() +} + func (w *responseWriter) WriteHeader(statusCode int) { if w.StatueCode != 0 { return