simpleHttpClient

package
v2.3.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 29, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProxyHttp   = "http"
	ProxyHttps  = "https"
	ProxySocks5 = "socks5"
)

Variables

This section is empty.

Functions

func InitHttpClient

func InitHttpClient(timeout time.Duration, args ...string) (*http.Client, error)

InitHttpClient 初始化http client Deprecated: 请使用 NewWithCache 或者 New

func New

func New(timeout time.Duration, args ...string) (*http.Client, error)

func NewWithCache

func NewWithCache(ck string, timeout time.Duration, args ...string) (*http.Client, error)

func NewWithProxy

func NewWithProxy(timeout time.Duration, proxy *cfg_proxy.Proxy) (*http.Client, error)

Types

type HttpClient

type HttpClient struct {
	NewClient    bool                                                `json:"new_client" yaml:"new_client" ini:"new_client"`          // 是否启用新的client
	EnableCookie bool                                                `json:"enable_cookie" yaml:"enable_cookie" ini:"enable_cookie"` // 是否启用cookie
	Timeout      time.Duration                                       `json:"timeout" yaml:"timeout" ini:"timeout"`                   // 超时时间
	Transport    `json:"transport" yaml:"transport" ini:"transport"` // 传输配置
}

func (HttpClient) InitClient

func (this HttpClient) InitClient() (*http.Client, error)

type Transport

type Transport struct {
	ProxyType              string        `json:"proxy_type" yaml:"proxy_type" ini:"proxy_type"`                                        // 代理类型 http,https,socks5
	ProxyAddr              string        `json:"proxy_addr" yaml:"proxy_addr" ini:"proxy_addr"`                                        // 代理地址
	InsecureSkipVerify     bool          `json:"insecure_skip_verify" yaml:"insecure_skip_verify" ini:"insecure_skip_verify"`          // 是否跳过证书验证
	TLSHandshakeTimeout    time.Duration `json:"tls_handshake_timeout" yaml:"tls_handshake_timeout" ini:"tls_handshake_timeout"`       // tls握手超时时间
	DisableKeepAlives      bool          `json:"disable_keep_alives" yaml:"disable_keep_alives" ini:"disable_keep_alives"`             // 是否禁用keepalives
	DisableCompression     bool          `json:"disable_compression" yaml:"disable_compression" ini:"disable_compression"`             // 是否禁用压缩
	MaxIdleConns           int           `json:"max_idle_conns" yaml:"max_idle_conns" ini:"max_idle_conns"`                            // 控制整个客户端的最大空闲连接数。值为0表示没有限制。
	MaxIdleConnsPerHost    int           `json:"max_idle_conns_per_host" yaml:"max_idle_conns_per_host" ini:"max_idle_conns_per_host"` // 限制每个主机的最大空闲连接数。同样地,0表示没有限制。
	MaxConnsPerHost        int           `json:"max_conns_per_host" yaml:"max_conns_per_host" ini:"max_conns_per_host"`                // 每个主机的最大连接数(包括活跃和空闲)。0表示无限制。
	IdleConnTimeout        time.Duration `json:"idle_conn_timeout" yaml:"idle_conn_timeout" ini:"idle_conn_timeout"`                   // 设置空闲连接在被关闭前等待新请求的时间长度。0表示不主动关闭空闲连接。
	ResponseHeaderTimeout  time.Duration `json:"response_header_timeout" yaml:"response_header_timeout" ini:"response_header_timeout"`
	ExpectContinueTimeout  time.Duration `json:"expect_continue_timeout" yaml:"expect_continue_timeout" ini:"expect_continue_timeout"`
	MaxResponseHeaderBytes int64         `json:"max_response_header_bytes" yaml:"max_response_header_bytes" ini:"max_response_header_bytes"`
	WriteBufferSize        int           `json:"write_buffer_size" yaml:"write_buffer_size" ini:"write_buffer_size"`
	ReadBufferSize         int           `json:"read_buffer_size" yaml:"read_buffer_size" ini:"read_buffer_size"`
	ForceAttemptHTTP2      bool          `json:"force_attempt_http2" yaml:"force_attempt_http2" ini:"force_attempt_http2"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL