mirror of
https://github.com/caddyserver/caddy.git
synced 2024-12-26 21:53:48 +03:00
reverseproxy: handle buffered data during hijack (#6274)
This commit is contained in:
parent
4d6370bf92
commit
1b9042bcdd
2 changed files with 13 additions and 0 deletions
|
@ -263,6 +263,8 @@ func (rr *responseRecorder) Hijack() (net.Conn, *bufio.ReadWriter, error) {
|
||||||
conn.(*hijackedConn).updateReadSize(buffered)
|
conn.(*hijackedConn).updateReadSize(buffered)
|
||||||
data, _ := brw.Peek(buffered)
|
data, _ := brw.Peek(buffered)
|
||||||
brw.Reader.Reset(io.MultiReader(bytes.NewReader(data), conn))
|
brw.Reader.Reset(io.MultiReader(bytes.NewReader(data), conn))
|
||||||
|
// peek to make buffered data appear, as Reset will make it 0
|
||||||
|
_, _ = brw.Peek(buffered)
|
||||||
} else {
|
} else {
|
||||||
brw.Reader.Reset(conn)
|
brw.Reader.Reset(conn)
|
||||||
}
|
}
|
||||||
|
|
|
@ -101,6 +101,17 @@ func (h *Handler) handleUpgradeResponse(logger *zap.Logger, wg *sync.WaitGroup,
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There may be buffered data in the *bufio.Reader
|
||||||
|
// see: https://github.com/caddyserver/caddy/issues/6273
|
||||||
|
if buffered := brw.Reader.Buffered(); buffered > 0 {
|
||||||
|
data, _ := brw.Peek(buffered)
|
||||||
|
_, err := backConn.Write(data)
|
||||||
|
if err != nil {
|
||||||
|
logger.Debug("backConn write failed", zap.Error(err))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Ensure the hijacked client connection, and the new connection established
|
// Ensure the hijacked client connection, and the new connection established
|
||||||
// with the backend, are both closed in the event of a server shutdown. This
|
// with the backend, are both closed in the event of a server shutdown. This
|
||||||
// is done by registering them. We also try to gracefully close connections
|
// is done by registering them. We also try to gracefully close connections
|
||||||
|
|
Loading…
Reference in a new issue