优化HTTP客户端管理

This commit is contained in:
GoEdgeLab
2024-04-17 18:24:21 +08:00
parent f248d4199e
commit cbf024b3ed
4 changed files with 35 additions and 24 deletions

View File

@@ -7,15 +7,17 @@ import (
// HTTPClient HTTP客户端
type HTTPClient struct {
rawClient *http.Client
accessAt int64
rawClient *http.Client
accessAt int64
isProxyProtocol bool
}
// NewHTTPClient 获取新客户端对象
func NewHTTPClient(rawClient *http.Client) *HTTPClient {
func NewHTTPClient(rawClient *http.Client, isProxyProtocol bool) *HTTPClient {
return &HTTPClient{
rawClient: rawClient,
accessAt: fasttime.Now().Unix(),
rawClient: rawClient,
accessAt: fasttime.Now().Unix(),
isProxyProtocol: isProxyProtocol,
}
}
@@ -34,6 +36,11 @@ func (this *HTTPClient) AccessTime() int64 {
return this.accessAt
}
// IsProxyProtocol 判断是否为PROXY Protocol
func (this *HTTPClient) IsProxyProtocol() bool {
return this.isProxyProtocol
}
// Close 关闭
func (this *HTTPClient) Close() {
this.rawClient.CloseIdleConnections()