mirror of
https://github.com/pgsty/minio.git
synced 2026-09-16 07:24:05 +03:00
fix(http): honor configured request header deadlines
Signed-off-by: Feng Ruohang <rh@vonng.com> (cherry picked from commit 0d48d32d7e038ae1ea5966f3d7e0cb86780a6311) Signed-off-by: Feng Ruohang <rh@vonng.com>
This commit is contained in:
@@ -29,6 +29,7 @@ import (
|
||||
"time"
|
||||
|
||||
"github.com/dustin/go-humanize"
|
||||
"github.com/minio/minio/internal/deadlineconn"
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -123,6 +124,32 @@ func (srv *Server) Init(listenCtx context.Context, listenErrCallback func(listen
|
||||
srv.listener = listener
|
||||
srv.listenerMutex.Unlock()
|
||||
|
||||
connState := srv.ConnState
|
||||
srv.ConnState = func(conn net.Conn, state http.ConnState) {
|
||||
raw := conn
|
||||
if tlsConn, ok := raw.(*tls.Conn); ok {
|
||||
if tlsConn.ConnectionState().NegotiatedProtocol == "h2" {
|
||||
// HTTP/2 owns its stream deadlines; do not change the connection.
|
||||
raw = nil
|
||||
} else {
|
||||
raw = tlsConn.NetConn()
|
||||
}
|
||||
}
|
||||
if dc, ok := raw.(*deadlineconn.DeadlineConn); ok {
|
||||
switch state {
|
||||
case http.StateNew, http.StateIdle:
|
||||
dc.SetReadDeadlineStrict(true)
|
||||
case http.StateActive:
|
||||
// net/http has finished reading the headers, including buffered
|
||||
// requests. Keep ReadTimeout as a rolling idle limit for uploads.
|
||||
dc.SetReadDeadlineStrict(false)
|
||||
}
|
||||
}
|
||||
if connState != nil {
|
||||
connState(conn, state)
|
||||
}
|
||||
}
|
||||
|
||||
var l net.Listener = listener
|
||||
if tlsConfig != nil {
|
||||
l = tls.NewListener(listener, tlsConfig)
|
||||
|
||||
Reference in New Issue
Block a user