Flush any written headers on Hijack

Closes #2108

Will make gin compatible with nhooyr.io/websocket.
This commit is contained in:
Anmol Sethi 2019-11-01 17:24:44 -04:00
parent db9174ae0c
commit b63e300299
No known key found for this signature in database
GPG Key ID: 8CEF1878FF10ADEB

View File

@ -101,6 +101,13 @@ func (w *responseWriter) Written() bool {
// Hijack implements the http.Hijacker interface.
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
// If the header was written but we did not write it to the
// underlying response writer yet, we need to.
// This matches the behaviour of net/http's Hijacker.
// See #2108.
if w.status != 0 && !w.Written() {
w.WriteHeaderNow()
}
if w.size < 0 {
w.size = 0
}