diff --git a/internal/nodes/client_conn.go b/internal/nodes/client_conn.go index 369dd8b..767de82 100644 --- a/internal/nodes/client_conn.go +++ b/internal/nodes/client_conn.go @@ -105,7 +105,7 @@ func (this *ClientConn) Read(b []byte) (n int, err error) { } // 设置读超时时间 - if this.isHTTP && !this.isWebsocket && !this.isShortReading && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && !this.isShortReading && this.autoReadTimeout { this.setHTTPReadTimeout() } @@ -172,7 +172,7 @@ func (this *ClientConn) Write(b []byte) (n int, err error) { } // 延长读超时时间 - if this.isHTTP && !this.isWebsocket && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && this.autoReadTimeout { this.setHTTPReadTimeout() } @@ -238,7 +238,7 @@ func (this *ClientConn) SetDeadline(t time.Time) error { func (this *ClientConn) SetReadDeadline(t time.Time) error { // 如果开启了HTTP自动读超时选项,则自动控制超时时间 - if this.isHTTP && !this.isWebsocket && this.autoReadTimeout { + if this.isHTTP && !this.isPersistent && this.autoReadTimeout { this.isShortReading = false var unixTime = t.Unix() diff --git a/internal/nodes/client_conn_base.go b/internal/nodes/client_conn_base.go index 62a0c87..3473a2a 100644 --- a/internal/nodes/client_conn_base.go +++ b/internal/nodes/client_conn_base.go @@ -16,7 +16,7 @@ type BaseClientConn struct { remoteAddr string hasLimit bool - isWebsocket bool + isPersistent bool // 是否为持久化连接 isClosed bool @@ -125,6 +125,6 @@ func (this *BaseClientConn) SetLinger(seconds int) error { return nil } -func (this *BaseClientConn) SetIsWebsocket(isWebsocket bool) { - this.isWebsocket = isWebsocket +func (this *BaseClientConn) SetIsPersistent(isPersistent bool) { + this.isPersistent = isPersistent } diff --git a/internal/nodes/client_conn_interface.go b/internal/nodes/client_conn_interface.go index 72a25b9..8026554 100644 --- a/internal/nodes/client_conn_interface.go +++ b/internal/nodes/client_conn_interface.go @@ -24,6 +24,6 @@ type ClientConnInterface interface { // UserId 获取当前连接所属服务的用户ID UserId() int64 - // SetIsWebsocket 设置是否为Websocket - SetIsWebsocket(isWebsocket bool) + // SetIsPersistent 设置是否为持久化 + SetIsPersistent(isPersistent bool) } diff --git a/internal/nodes/client_tls_conn.go b/internal/nodes/client_tls_conn.go index e5b7d18..69335d9 100644 --- a/internal/nodes/client_tls_conn.go +++ b/internal/nodes/client_tls_conn.go @@ -56,14 +56,14 @@ func (this *ClientTLSConn) SetWriteDeadline(t time.Time) error { return this.rawConn.SetWriteDeadline(t) } -func (this *ClientTLSConn) SetIsWebsocket(isWebsocket bool) { +func (this *ClientTLSConn) SetIsPersistent(isPersistent bool) { tlsConn, ok := this.rawConn.(*tls.Conn) if ok { var rawConn = tlsConn.NetConn() if rawConn != nil { clientConn, ok := rawConn.(*ClientConn) if ok { - clientConn.SetIsWebsocket(isWebsocket) + clientConn.SetIsPersistent(isPersistent) } } } diff --git a/internal/nodes/http_request_fastcgi.go b/internal/nodes/http_request_fastcgi.go index 520af44..325249f 100644 --- a/internal/nodes/http_request_fastcgi.go +++ b/internal/nodes/http_request_fastcgi.go @@ -73,6 +73,16 @@ func (this *HTTPRequest) doFastcgi() (shouldStop bool) { } } + // 设置为持久化连接 + var requestConn = this.RawReq.Context().Value(HTTPConnContextKey) + if requestConn == nil { + return + } + requestClientConn, ok := requestConn.(ClientConnInterface) + if ok { + requestClientConn.SetIsPersistent(true) + } + // 连接池配置 poolSize := fastcgi.PoolSize if poolSize <= 0 { diff --git a/internal/nodes/http_request_websocket.go b/internal/nodes/http_request_websocket.go index ea04f7f..014e2e9 100644 --- a/internal/nodes/http_request_websocket.go +++ b/internal/nodes/http_request_websocket.go @@ -111,7 +111,7 @@ func (this *HTTPRequest) doWebsocket(requestHost string, isLastRetry bool) (shou requestClientConn, ok := requestConn.(ClientConnInterface) if ok { - requestClientConn.SetIsWebsocket(true) + requestClientConn.SetIsPersistent(true) } clientConn, _, err := this.writer.Hijack()