From e79a88856a6c093720843e4124c8144c804f472d Mon Sep 17 00:00:00 2001 From: Tw Date: Fri, 12 Jun 2015 11:42:28 +0800 Subject: [PATCH] let middleware.responseRecorder be a http.Hijacker Signed-off-by: Tw --- middleware/recorder.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/middleware/recorder.go b/middleware/recorder.go index 4884026c..0477cce8 100644 --- a/middleware/recorder.go +++ b/middleware/recorder.go @@ -1,6 +1,9 @@ package middleware import ( + "bufio" + "errors" + "net" "net/http" "time" ) @@ -48,3 +51,12 @@ func (r *responseRecorder) Write(buf []byte) (int, error) { } return n, err } + +// Hijacker is a wrapper of http.Hijacker underearth if any, +// otherwise it just returns an error. +func (r *responseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) { + if hj, ok := r.ResponseWriter.(http.Hijacker); ok { + return hj.Hijack() + } + return nil, nil, errors.New("I'm not a Hijacker") +}