mirror of
https://github.com/gin-gonic/gin.git
synced 2025-10-15 04:33:40 +08:00
Merge b6a995d26f38dfc082d304733300e5f18ba5e3eb into 4103061a4a8d977fe0700e89b13c3ce51ec1d92f
This commit is contained in:
commit
ca4bdfca6c
@ -26,13 +26,15 @@ type (
|
|||||||
Status() int
|
Status() int
|
||||||
Size() int
|
Size() int
|
||||||
Written() bool
|
Written() bool
|
||||||
|
Hijacked() bool
|
||||||
WriteHeaderNow()
|
WriteHeaderNow()
|
||||||
}
|
}
|
||||||
|
|
||||||
responseWriter struct {
|
responseWriter struct {
|
||||||
http.ResponseWriter
|
http.ResponseWriter
|
||||||
status int
|
status int
|
||||||
size int
|
size int
|
||||||
|
hijacked bool
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,7 +54,7 @@ func (w *responseWriter) WriteHeader(code int) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (w *responseWriter) WriteHeaderNow() {
|
func (w *responseWriter) WriteHeaderNow() {
|
||||||
if !w.Written() {
|
if !w.Written() && !w.Hijacked() {
|
||||||
w.size = 0
|
w.size = 0
|
||||||
w.ResponseWriter.WriteHeader(w.status)
|
w.ResponseWriter.WriteHeader(w.status)
|
||||||
}
|
}
|
||||||
@ -77,12 +79,17 @@ func (w *responseWriter) Written() bool {
|
|||||||
return w.size != NoWritten
|
return w.size != NoWritten
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (w *responseWriter) Hijacked() bool {
|
||||||
|
return w.hijacked
|
||||||
|
}
|
||||||
|
|
||||||
// Implements the http.Hijacker interface
|
// Implements the http.Hijacker interface
|
||||||
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
hijacker, ok := w.ResponseWriter.(http.Hijacker)
|
hijacker, ok := w.ResponseWriter.(http.Hijacker)
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface")
|
return nil, nil, errors.New("the ResponseWriter doesn't support the Hijacker interface")
|
||||||
}
|
}
|
||||||
|
w.hijacked = true
|
||||||
return hijacker.Hijack()
|
return hijacker.Hijack()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user