mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-23 22:27:38 -05:00
gzip: Implement http.Hijacker (fixes #635)
This commit is contained in:
parent
72fcdec8d8
commit
05957b4965
2 changed files with 14 additions and 3 deletions
|
@ -3,10 +3,12 @@
|
|||
package gzip
|
||||
|
||||
import (
|
||||
"bufio"
|
||||
"compress/gzip"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
@ -130,3 +132,12 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) {
|
|||
n, err := w.Writer.Write(b)
|
||||
return n, err
|
||||
}
|
||||
|
||||
// Hijack implements http.Hijacker. It simply wraps the underlying
|
||||
// ResponseWriter's Hijack method if there is one, or returns an error.
|
||||
func (w *gzipResponseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||
if hj, ok := w.ResponseWriter.(http.Hijacker); ok {
|
||||
return hj.Hijack()
|
||||
}
|
||||
return nil, nil, fmt.Errorf("not a Hijacker")
|
||||
}
|
||||
|
|
|
@ -62,11 +62,11 @@ func (r *ResponseRecorder) Status() int {
|
|||
return r.status
|
||||
}
|
||||
|
||||
// Hijacker is a wrapper of http.Hijacker underearth if any,
|
||||
// otherwise it just returns an error.
|
||||
// Hijack implements http.Hijacker. It simply wraps the underlying
|
||||
// ResponseWriter's Hijack method if there is one, or 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")
|
||||
return nil, nil, errors.New("not a Hijacker")
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue