Files
EdgeNode/internal/nodes/http_client.go

48 lines
1.0 KiB
Go
Raw Normal View History

2020-09-27 15:26:06 +08:00
package nodes
import (
"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
2020-09-27 15:26:06 +08:00
"net/http"
)
2021-04-19 19:29:32 +08:00
// HTTPClient HTTP客户端
2020-09-27 15:26:06 +08:00
type HTTPClient struct {
2024-04-17 18:24:21 +08:00
rawClient *http.Client
accessAt int64
isProxyProtocol bool
2020-09-27 15:26:06 +08:00
}
2021-04-19 19:29:32 +08:00
// NewHTTPClient 获取新客户端对象
2024-04-17 18:24:21 +08:00
func NewHTTPClient(rawClient *http.Client, isProxyProtocol bool) *HTTPClient {
2020-09-27 15:26:06 +08:00
return &HTTPClient{
2024-04-17 18:24:21 +08:00
rawClient: rawClient,
accessAt: fasttime.Now().Unix(),
isProxyProtocol: isProxyProtocol,
2020-09-27 15:26:06 +08:00
}
}
2021-04-19 19:29:32 +08:00
// RawClient 获取原始客户端对象
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) RawClient() *http.Client {
return this.rawClient
}
2021-04-19 19:29:32 +08:00
// UpdateAccessTime 更新访问时间
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) UpdateAccessTime() {
this.accessAt = fasttime.Now().Unix()
2020-09-27 15:26:06 +08:00
}
2021-04-19 19:29:32 +08:00
// AccessTime 获取访问时间
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) AccessTime() int64 {
return this.accessAt
}
2024-04-17 18:24:21 +08:00
// IsProxyProtocol 判断是否为PROXY Protocol
func (this *HTTPClient) IsProxyProtocol() bool {
return this.isProxyProtocol
}
2021-04-19 19:29:32 +08:00
// Close 关闭
2020-09-27 15:26:06 +08:00
func (this *HTTPClient) Close() {
this.rawClient.CloseIdleConnections()
}