diff --git a/encoding/gzip.go b/encoding/gzip.go index d84250b..cce3ce6 100644 --- a/encoding/gzip.go +++ b/encoding/gzip.go @@ -9,8 +9,11 @@ Package encoding contains Content-Encoding related filters. package encoding import ( + "bufio" "compress/gzip" + "errors" "io" + "net" "net/http" "strings" "sync" @@ -58,6 +61,13 @@ func (w *gzipWriter) WriteHeader(code int) { w.ResponseWriter.WriteHeader(code) } +func (w *gzipWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) { + if hj, ok := w.ResponseWriter.(http.Hijacker); ok { + return hj.Hijack() + } + return nil, nil, errors.New("not a Hijacker") +} + func (w *gzipWriter) init() error { w.Lock() defer w.Unlock() diff --git a/encoding/gzip_test.go b/encoding/gzip_test.go index 42911bf..360ce7d 100644 --- a/encoding/gzip_test.go +++ b/encoding/gzip_test.go @@ -153,3 +153,20 @@ func TestGzipper_WriteHeader(t *testing.T) { } } } + +func TestGzipper_Hijacker(t *testing.T) { + srv := httptest.NewServer(Gzipper(gzip.DefaultCompression)( + http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { + if _, ok := w.(http.Hijacker); !ok { + t.Error("underlying http.ResponseWriter should implement http.Hijacker") + } + }), + )) + defer srv.Close() + + resp, err := http.Get(srv.URL) + if err != nil { + t.Fatal(err) + } + resp.Body.Close() +}