docs(response): clarify Hijack writer state behavior

This commit is contained in:
lihainuo 2026-10-13 10:09:36 +08:00
parent 649e321fc7
commit 671f6b691c

View File

@ -108,6 +108,7 @@ func (w *responseWriter) Written() bool {
}
// Hijack implements the http.Hijacker interface.
// On error, the writer state is left unchanged so callers can send a fallback HTTP response.
func (w *responseWriter) Hijack() (net.Conn, *bufio.ReadWriter, error) {
// 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)