mirror of https://github.com/gin-gonic/gin.git
Hijacker interface added
This commit is contained in:
parent
b3f322c5fc
commit
4a24c47a69
|
@ -1,7 +1,10 @@
|
||||||
package gin
|
package gin
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bufio"
|
||||||
|
"errors"
|
||||||
"log"
|
"log"
|
||||||
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,6 +14,7 @@ type (
|
||||||
Status() int
|
Status() int
|
||||||
Written() bool
|
Written() bool
|
||||||
WriteHeaderNow()
|
WriteHeaderNow()
|
||||||
|
Hijack() (net.Conn, *bufio.ReadWriter, error)
|
||||||
}
|
}
|
||||||
|
|
||||||
responseWriter struct {
|
responseWriter struct {
|
||||||
|
@ -54,3 +58,12 @@ func (w *responseWriter) Status() int {
|
||||||
func (w *responseWriter) Written() bool {
|
func (w *responseWriter) Written() bool {
|
||||||
return w.written
|
return w.written
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// allow connection hijacking
|
||||||
|
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
|
hijacker, ok := w.ResponseWriter.(http.Hijacker)
|
||||||
|
if !ok {
|
||||||
|
return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface")
|
||||||
|
}
|
||||||
|
return hijacker.Hijack()
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue