]> Cypherpunks.ru repositories - gostls13.git/blobdiff - src/net/http/responsecontroller.go
net/http: support full-duplex HTTP/1 responses
[gostls13.git] / src / net / http / responsecontroller.go
index 018bdc00eb77a1f2a2381b6f3f8e3031d105737b..92276ffaf2344c02ae03e290b33caf3c819583b5 100644 (file)
@@ -31,6 +31,7 @@ type ResponseController struct {
 //     Hijack() (net.Conn, *bufio.ReadWriter, error)
 //     SetReadDeadline(deadline time.Time) error
 //     SetWriteDeadline(deadline time.Time) error
+//     EnableFullDuplex() error
 //
 // If the ResponseWriter does not support a method, ResponseController returns
 // an error matching ErrNotSupported.
@@ -115,6 +116,30 @@ func (c *ResponseController) SetWriteDeadline(deadline time.Time) error {
        }
 }
 
+// EnableFullDuplex indicates that 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 EnableFullDuplex 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) EnableFullDuplex() error {
+       rw := c.rw
+       for {
+               switch t := rw.(type) {
+               case interface{ EnableFullDuplex() error }:
+                       return t.EnableFullDuplex()
+               case rwUnwrapper:
+                       rw = t.Unwrap()
+               default:
+                       return errNotSupported()
+               }
+       }
+}
+
 // errNotSupported returns an error that Is ErrNotSupported,
 // but is not == to it.
 func errNotSupported() error {