diff --git a/src/net/http/server.go b/src/net/http/server.go index f095b7edd2..d90418b56d 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -964,14 +964,14 @@ func (c *conn) readRequest(ctx context.Context) (w *response, err error) { hdrDeadline time.Time // or zero if none ) t0 := time.Now() - if d := c.server.readHeaderTimeout(); d != 0 { + if d := c.server.readHeaderTimeout(); d > 0 { hdrDeadline = t0.Add(d) } - if d := c.server.ReadTimeout; d != 0 { + if d := c.server.ReadTimeout; d > 0 { wholeReqDeadline = t0.Add(d) } c.rwc.SetReadDeadline(hdrDeadline) - if d := c.server.WriteTimeout; d != 0 { + if d := c.server.WriteTimeout; d > 0 { defer func() { c.rwc.SetWriteDeadline(time.Now().Add(d)) }() @@ -1831,10 +1831,10 @@ func (c *conn) serve(ctx context.Context) { }() if tlsConn, ok := c.rwc.(*tls.Conn); ok { - if d := c.server.ReadTimeout; d != 0 { + if d := c.server.ReadTimeout; d > 0 { c.rwc.SetReadDeadline(time.Now().Add(d)) } - if d := c.server.WriteTimeout; d != 0 { + if d := c.server.WriteTimeout; d > 0 { c.rwc.SetWriteDeadline(time.Now().Add(d)) } if err := tlsConn.HandshakeContext(ctx); err != nil { @@ -2567,7 +2567,8 @@ type Server struct { TLSConfig *tls.Config // ReadTimeout is the maximum duration for reading the entire - // request, including the body. + // request, including the body. A zero or negative value means + // there will be no timeout. // // Because ReadTimeout does not let Handlers make per-request // decisions on each request body's acceptable deadline or @@ -2587,6 +2588,7 @@ type Server struct { // writes of the response. It is reset whenever a new // request's header is read. Like ReadTimeout, it does not // let Handlers make decisions on a per-request basis. + // A zero or negative value means there will be no timeout. WriteTimeout time.Duration // IdleTimeout is the maximum amount of time to wait for the