From 4a24c47a69f56e8275ef330beca3c2925d270948 Mon Sep 17 00:00:00 2001 From: olebedev Date: Mon, 25 Aug 2014 15:58:43 +0400 Subject: [PATCH] Hijacker interface added --- response_writer.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/response_writer.go b/response_writer.go index 91afe89b..4a65daf4 100644 --- a/response_writer.go +++ b/response_writer.go @@ -1,7 +1,10 @@ package gin import ( + "bufio" + "errors" "log" + "net" "net/http" ) @@ -11,6 +14,7 @@ type ( Status() int Written() bool WriteHeaderNow() + Hijack() (net.Conn, *bufio.ReadWriter, error) } responseWriter struct { @@ -54,3 +58,12 @@ func (w *responseWriter) Status() int { func (w *responseWriter) Written() bool { return w.written } + +// allow connection hijacking +func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + hijacker, ok := w.ResponseWriter.(http.Hijacker) + if !ok { + return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface") + } + return hijacker.Hijack() +}