mirror of
https://github.com/caddyserver/caddy.git
synced 2025-01-13 22:51:08 -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
|
package gzip
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
"compress/gzip"
|
"compress/gzip"
|
||||||
"fmt"
|
"fmt"
|
||||||
"io"
|
"io"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -130,3 +132,12 @@ func (w *gzipResponseWriter) Write(b []byte) (int, error) {
|
||||||
n, err := w.Writer.Write(b)
|
n, err := w.Writer.Write(b)
|
||||||
return n, err
|
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
|
return r.status
|
||||||
}
|
}
|
||||||
|
|
||||||
// Hijacker is a wrapper of http.Hijacker underearth if any,
|
// Hijack implements http.Hijacker. It simply wraps the underlying
|
||||||
// otherwise it just returns an error.
|
// ResponseWriter's Hijack method if there is one, or returns an error.
|
||||||
func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
func (r *ResponseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
if hj, ok := r.ResponseWriter.(http.Hijacker); ok {
|
if hj, ok := r.ResponseWriter.(http.Hijacker); ok {
|
||||||
return hj.Hijack()
|
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