Skip to content

Commit 05957b4

Browse files
committed
gzip: Implement http.Hijacker (fixes #635)
1 parent 72fcdec commit 05957b4

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

middleware/gzip/gzip.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,12 @@
33
package gzip
44

55
import (
6+
"bufio"
67
"compress/gzip"
78
"fmt"
89
"io"
910
"io/ioutil"
11+
"net"
1012
"net/http"
1113
"strings"
1214

@@ -130,3 +132,12 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) {
130132
n, err := w.Writer.Write(b)
131133
return n, err
132134
}
135+
136+
// Hijack implements http.Hijacker. It simply wraps the underlying
137+
// ResponseWriter's Hijack method if there is one, or returns an error.
138+
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
139+
if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
140+
return hj.Hijack()
141+
}
142+
return nil, nil, fmt.Errorf("not a Hijacker")
143+
}

middleware/recorder.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,11 +62,11 @@ func (r *ResponseRecorder) Status() int {
6262
return r.status
6363
}
6464

65-
// Hijacker is a wrapper of http.Hijacker underearth if any,
66-
// otherwise it just returns an error.
65+
// Hijack implements http.Hijacker. It simply wraps the underlying
66+
// ResponseWriter's Hijack method if there is one, or returns an error.
6767
func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
6868
if hj, ok := r.ResponseWriter.(http.Hijacker); ok {
6969
return hj.Hijack()
7070
}
71-
return nil, nil, errors.New("I'm not a Hijacker")
71+
return nil, nil, errors.New("not a Hijacker")
7272
}

0 commit comments

Comments
 (0)