-
Notifications
You must be signed in to change notification settings - Fork 18.3k
Closed
Description
This proposal aims to address #15527.
The net/http
HTTP/1 server does not permit reading from an inbound request body after starting to write the response. (See the ResponseWriter.Write
documentation).
This limitation is because the server drains any unread portion of the request body before writing the response headers, to avoid deadlocking clients that attempt to write a complete request before reading the response. (See #15527 (comment) for more context.)
I propose that we offer an opt-in mechanism to disable this behavior, permitting a server handler to write some or all of the response interleaved with reads from the request.
// SetBidi indicates whether the request handler will interleave reads from Request.Body with
// writes to the ResponseWriter.
//
// For HTTP/1 requests, the Go HTTP server by default consumes any unread portion of the request
// body before beginning to write the response, preventing handlers from concurrently reading from
// the request and writing the response. Calling SetBidi(true) disables this behavior and permits
// handlers to continue to read from the request while concurrently writing the response.
//
// For HTTP/2 requests, the Go HTTP server always permits concurrent reads and responses.
func (c *ResponseController) SetBidi(bidi bool) error {}
packet-sent, johanbrandhorst, cpuguy83, rustatian, jerome-laforge and 6 morenwtgck, moadi, fraidev, herrberk and nikolaydimitrovkomuw and herrberk