Update response_writer.go

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This commit is contained in:
Bo-Yi Wu 2025-09-24 23:50:54 +08:00 committed by GitHub
parent 1dca635ea2
commit 48e89fbe69
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -109,8 +109,8 @@ func (w *responseWriter) Written() bool {
// Hijack implements the http.Hijacker interface.
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
// Allow hijacking after headers are written (size == 0), but not after body data (size > 0)
// For compatibility with websocket libraries (e.g., github.com/coder/websocket)
// Allow hijacking before any data is written (size == -1) or after headers are written (size == 0),
// but not after body data is written (size > 0). For compatibility with websocket libraries (e.g., github.com/coder/websocket)
if w.size > 0 {
return nil, nil, errHijackAlreadyWritten
}