github.com/TeaOSLab/EdgeNode@v1.3.8/internal/nodes/http_client.go (about)

     1  package nodes
     2  
     3  import (
     4  	"github.com/TeaOSLab/EdgeNode/internal/utils/fasttime"
     5  	"net/http"
     6  )
     7  
     8  // HTTPClient HTTP客户端
     9  type HTTPClient struct {
    10  	rawClient       *http.Client
    11  	accessAt        int64
    12  	isProxyProtocol bool
    13  }
    14  
    15  // NewHTTPClient 获取新客户端对象
    16  func NewHTTPClient(rawClient *http.Client, isProxyProtocol bool) *HTTPClient {
    17  	return &HTTPClient{
    18  		rawClient:       rawClient,
    19  		accessAt:        fasttime.Now().Unix(),
    20  		isProxyProtocol: isProxyProtocol,
    21  	}
    22  }
    23  
    24  // RawClient 获取原始客户端对象
    25  func (this *HTTPClient) RawClient() *http.Client {
    26  	return this.rawClient
    27  }
    28  
    29  // UpdateAccessTime 更新访问时间
    30  func (this *HTTPClient) UpdateAccessTime() {
    31  	this.accessAt = fasttime.Now().Unix()
    32  }
    33  
    34  // AccessTime 获取访问时间
    35  func (this *HTTPClient) AccessTime() int64 {
    36  	return this.accessAt
    37  }
    38  
    39  // IsProxyProtocol 判断是否为PROXY Protocol
    40  func (this *HTTPClient) IsProxyProtocol() bool {
    41  	return this.isProxyProtocol
    42  }
    43  
    44  // Close 关闭
    45  func (this *HTTPClient) Close() {
    46  	this.rawClient.CloseIdleConnections()
    47  }