Documentation ¶
Index ¶
- Constants
- func AddCookie(cookie *http.Cookie)
- func AddCookies(cookies []*http.Cookie)
- func Cookies(url string) ([]*http.Cookie, error)
- func DelCookie(cookie *http.Cookie)
- func GeneratorWithConfig(config *Config) func(*url.URL, proxy.Dialer) (proxy.Dialer, error)
- func Get(url string) (statusCode int, resp []byte, err error)
- func NewConnectproxy(u *url.URL, forward proxy.Dialer) (proxy.Dialer, error)
- func NewWithConfig(u *url.URL, forward proxy.Dialer, config *Config) (proxy.Dialer, error)
- func Post(url, contentType string, body interface{}) (statusCode int, resp []byte, err error)
- func RegisterDialerFromURL(registerHTTP, registerHTTPS bool)
- type Client
- func NewClient(opts ...ClientOption) *Client
- func NewClientHttp2(opts ...ClientOption) *Client
- func NewDefaultClient(opts ...ClientOption) *Client
- func NewWithClient(hc *http.Client, opts ...ClientOption) *Client
- func SetCheckProxy(checkProxy func(response *Response) bool) *Client
- func SetCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) *Client
- func SetIdleConnTimeout(timeout time.Duration) *Client
- func SetJar(jar http.CookieJar) *Client
- func SetMaxConnsPerHost(n int) *Client
- func SetMaxIdleConns(n int) *Client
- func SetMaxIdleConnsPerHost(n int) *Client
- func SetMetadata(mds ...map[string]string) *Client
- func SetProxy(scheme, ip, port, username, password string) *Client
- func SetProxySelector(selector ProxySelector) *Client
- func SetProxyURL(proxyURL string) *Client
- func SetTimeout(timeout time.Duration) *Client
- func SetTransport(rt http.RoundTripper) *Client
- func (c *Client) AddCookie(cookie *http.Cookie) *Client
- func (c *Client) AddCookies(cookies []*http.Cookie) *Client
- func (c *Client) Cookies(url string) ([]*http.Cookie, error)
- func (c *Client) DelCookie(cookie *http.Cookie) *Client
- func (c *Client) Get(url string) (statusCode int, resp []byte, err error)
- func (c *Client) GetCookieJar() http.CookieJar
- func (c *Client) GetMetaDataByKey(key string) string
- func (c *Client) KeepParamAddOrder(keepParamAddOrder bool) *Client
- func (c *Client) NewRequest(method, url string) *Request
- func (c *Client) NewRequestWithContext(ctx context.Context, method, url string) *Request
- func (c *Client) Post(url, contentType string, body interface{}) (statusCode int, resp []byte, err error)
- func (c *Client) SetCookie(cookie *http.Cookie) *Client
- func (c *Client) SetCookieJar(cookieJar http.CookieJar)
- func (c *Client) SetCookies(cookies []*http.Cookie) *Client
- func (c *Client) SetJsonEscapeHTML(jsonEscapeHTML bool) *Client
- func (c *Client) SetJsonIndent(prefix, indent string) *Client
- func (c *Client) SetProxy(ps ProxySelector) *Client
- func (c *Client) SetTimeout(timeout time.Duration) *Client
- func (c *Client) SetTransport(transport http.RoundTripper) *Client
- type ClientOption
- func WithCheckProxy(checkProxy func(response *Response) bool) ClientOption
- func WithCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) ClientOption
- func WithIdleConnTimeout(timeout time.Duration) ClientOption
- func WithJar(jar http.CookieJar) ClientOption
- func WithMaxConnsPerHost(n int) ClientOption
- func WithMaxIdleConns(n int) ClientOption
- func WithMaxIdleConnsPerHost(n int) ClientOption
- func WithMetadata(mds ...map[string]string) ClientOption
- func WithProxySelector(selector ProxySelector) ClientOption
- func WithTimeout(timeout time.Duration) ClientOption
- func WithTransport(rt http.RoundTripper) ClientOption
- type Config
- type Debug
- type DecryptFunc
- type ErrorConnectionTimeout
- type ErrorUnsupportedScheme
- type HostnameProxySelector
- type Ja3Slice
- type ProxySelector
- type ProxyURLSelector
- type Request
- func (r *Request) AddCookie(cookie *http.Cookie) *Request
- func (r *Request) AddCookies(cookies []*http.Cookie) *Request
- func (r *Request) AddHead(key, value string) *Request
- func (r *Request) AddHeads(headers http.Header) *Request
- func (r *Request) Byte() (statusCode int, resp []byte, err error)
- func (r *Request) Context() context.Context
- func (r *Request) CustomRequest(f func(request *Request)) *Request
- func (r *Request) Do() (*Response, error)
- func (r *Request) GetUrl() string
- func (r *Request) KeepQueryParamOrder(keepParamAddOrder bool) *Request
- func (r *Request) SetBody(contentType string, body interface{}) *Request
- func (r *Request) SetCheckProxy(checkProxy func(response *Response) bool) *Request
- func (r *Request) SetCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) *Request
- func (r *Request) SetClient(cli *Client) *Request
- func (r *Request) SetFormData(key, value string) *Request
- func (r *Request) SetHead(key, value string) *Request
- func (r *Request) SetHeads(headers http.Header) *Request
- func (r *Request) SetJsonEscapeHTML() *Request
- func (r *Request) SetJsonIndent(prefix, indent string) *Request
- func (r *Request) SetQueryParam(key, value string) *Request
- func (r *Request) SetQueryParams(params map[string]string) *Request
- func (r *Request) SetRawFormData(formData map[string]string) *Request
- func (r *Request) SetRawHead(key, value string) *Request
- func (r *Request) SetRawHeads(heads map[string]string) *Request
- func (r *Request) String() (statusCode int, resp string, err error)
- func (r *Request) StringWithDecrypt(decrypt DecryptFunc) (statusCode int, resp string, err error)
- func (r *Request) Unmarshal(val interface{}) (err error)
- func (r *Request) UnmarshalWithDecrypt(decrypt DecryptFunc, val interface{}) (err error)
- func (r *Request) WithContext(ctx context.Context) *Request
- type Response
- func (r *Response) Body() (body []byte, err error)
- func (r *Response) Cookies() []*http.Cookie
- func (r *Response) FromJSON(v interface{}) error
- func (r *Response) Headers() http.Header
- func (r *Response) Location() (*stdurl.URL, error)
- func (r *Response) Response() *http.Response
- func (r *Response) StatusCode() int
- func (r *Response) ToFile(filename string) error
- type TlsConnOption
- func WithHandShakeTimeout(handShakeTimeout time.Duration) TlsConnOption
- func WithTcpDialTimeout(dialTimeout time.Duration) TlsConnOption
- func WithTlsConnOptClientHelloID(id tls.ClientHelloID) TlsConnOption
- func WithTlsConnOptClientHelloSpec(spec *tls.ClientHelloSpec) TlsConnOption
- func WithTlsConnOptProxyAddr(proxyAddr string) TlsConnOption
- type Transport
Constants ¶
const ( MIMEJSON = "application/json" MIMEHTML = "text/html" MIMEXML = "application/xml" MIMETextXML = "text/xml" MIMEPlain = "text/plain" MIMEPOSTForm = "application/x-www-form-urlencoded" MIMEMultipartPOSTForm = "multipart/form-data" MIMEXPROTOBUF = "application/x-protobuf" MIMEXMSGPACK = "application/x-msgpack" MIMEMSGPACK = "application/msgpack" MIMEYAML = "application/x-yaml" )
Content-Type https://www.iana.org/assignments/media-types/media-types.xhtml
Variables ¶
This section is empty.
Functions ¶
func AddCookies ¶
func GeneratorWithConfig ¶
GeneratorWithConfig is like NewWithConfig, but is suitable for passing to proxy.RegisterDialerType while maintaining configuration options.
This is to enable registration of an http(s) proxy with options, e.g.:
proxy.RegisterDialerType("https", connectproxy.GeneratorWithConfig( &connectproxy.Config{DialTimeout: 5 * time.Minute}, ))
func NewConnectproxy ¶
NewConnectproxy returns a proxy.Dialer given a URL specification and an underlying proxy.Dialer for it to make network requests. NewConnectproxy may be passed to proxy.RegisterDialerType for the schemes "http" and "https". The convenience function RegisterDialerFromURL simplifies this.
func NewWithConfig ¶
NewWithConfig is like NewConnectproxy, but allows control over various options.
func RegisterDialerFromURL ¶
func RegisterDialerFromURL(registerHTTP, registerHTTPS bool)
RegisterDialerFromURL is a convenience wrapper around proxy.RegisterDialerType, which registers the given URL as a for the schemes "http" and/or "https", as controlled by registerHTTP and registerHTTPS. If both registerHTTP and registerHTTPS are false, RegisterDialerFromURL is a no-op.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
func NewClient ¶
func NewClient(opts ...ClientOption) *Client
func NewClientHttp2 ¶
func NewClientHttp2(opts ...ClientOption) *Client
func NewDefaultClient ¶
func NewDefaultClient(opts ...ClientOption) *Client
func NewWithClient ¶
func NewWithClient(hc *http.Client, opts ...ClientOption) *Client
func SetCheckProxy ¶
func SetCheckRedirect ¶
func SetIdleConnTimeout ¶
func SetMaxConnsPerHost ¶
func SetMaxIdleConns ¶
func SetMaxIdleConnsPerHost ¶
func SetMetadata ¶
func SetProxy ¶
SetProxy http 127.0.0.1 8888 http 127.0.0.1 8888 username password socks5 127.0.0.1 8888 username password
func SetProxySelector ¶
func SetProxySelector(selector ProxySelector) *Client
func SetProxyURL ¶
SetProxyURL Proxy:http://127.0.0.1:8888 Proxy:http://username:password@127.0.0.1:8888
func SetTimeout ¶
func SetTransport ¶
func SetTransport(rt http.RoundTripper) *Client
func (*Client) GetCookieJar ¶
func (*Client) GetMetaDataByKey ¶
GetMetaDataByKey 通过key获取metadata
func (*Client) KeepParamAddOrder ¶
func (*Client) NewRequest ¶
func (*Client) NewRequestWithContext ¶
func (*Client) SetCookieJar ¶
func (*Client) SetJsonEscapeHTML ¶
func (*Client) SetJsonIndent ¶
func (*Client) SetProxy ¶
func (c *Client) SetProxy(ps ProxySelector) *Client
SetProxy 设置代理时保证用底层共用一个client
func (*Client) SetTransport ¶
func (c *Client) SetTransport(transport http.RoundTripper) *Client
type ClientOption ¶
type ClientOption func(*Client)
func WithCheckProxy ¶
func WithCheckProxy(checkProxy func(response *Response) bool) ClientOption
func WithCheckRedirect ¶
func WithIdleConnTimeout ¶
func WithIdleConnTimeout(timeout time.Duration) ClientOption
func WithJar ¶
func WithJar(jar http.CookieJar) ClientOption
func WithMaxConnsPerHost ¶
func WithMaxConnsPerHost(n int) ClientOption
func WithMaxIdleConns ¶
func WithMaxIdleConns(n int) ClientOption
func WithMaxIdleConnsPerHost ¶
func WithMaxIdleConnsPerHost(n int) ClientOption
func WithMetadata ¶
func WithMetadata(mds ...map[string]string) ClientOption
func WithProxySelector ¶
func WithProxySelector(selector ProxySelector) ClientOption
func WithTimeout ¶
func WithTimeout(timeout time.Duration) ClientOption
func WithTransport ¶
func WithTransport(rt http.RoundTripper) ClientOption
type Config ¶
type Config struct { // ServerName is the name to use in the TLS connection to (not through) // the proxy server if different from the host in the URL. // Specifically, this is used in the ServerName field of the // *tls.Config used in connections to TLS-speaking proxy servers. ServerName string // For proxy servers supporting TLS connections (to, not through), // skip TLS certificate validation. InsecureSkipVerify bool // Passed directly to tls.Dial // Header sets the headers in the initial HTTP CONNECT request. See // the documentation for http.Request for more information. Header http.Header // DialTimeout is an optional timeout for connections through (not to) // the proxy server. DialTimeout time.Duration }
Config allows various parameters to be configured. It is used with NewWithConfig. The config passed to NewWithConfig may be changed between requests. If it is, the changes will affect all current and future invocations of the returned proxy.Dialer's Dial method.
type Debug ¶
type Debug struct { TlsConnCount map[string]int64 // 此host建立过多少个tls链接 TlsHandShakeTime map[string]int64 // 与host建立tls链接的tls握手时延, 毫秒 // contains filtered or unexported fields }
func (*Debug) GetTlsConnCount ¶
func (*Debug) GetTlsHandShakeTime ¶
func (*Debug) IncrTlsConnCount ¶
func (*Debug) SetTlsHandShakeTime ¶
type DecryptFunc ¶
type ErrorConnectionTimeout ¶
type ErrorConnectionTimeout error
ErrorConnectionTimeout is returned if the connection through the proxy server was not able to be made before the configured timeout expired.
type ErrorUnsupportedScheme ¶
type ErrorUnsupportedScheme error
ErrorUnsupportedScheme is returned if a scheme other than "http" or "https" is used.
type HostnameProxySelector ¶
type HostnameProxySelector struct {
// contains filtered or unexported fields
}
HostnameProxySelector 特定 Hostname 使用特定代理
func NewHostNameProxySelector ¶
func NewHostNameProxySelector(proxyInvalid func(ctx context.Context)) *HostnameProxySelector
func (*HostnameProxySelector) ProxyInvalid ¶
func (s *HostnameProxySelector) ProxyInvalid(ctx context.Context)
func (*HostnameProxySelector) SetProxyURL ¶
func (s *HostnameProxySelector) SetProxyURL(proxy *url.URL, urls ...string) error
type ProxySelector ¶
type ProxyURLSelector ¶
type ProxyURLSelector struct {
// contains filtered or unexported fields
}
func NewProxyURLSelector ¶
func (*ProxyURLSelector) ProxyInvalid ¶
func (s *ProxyURLSelector) ProxyInvalid(ctx context.Context)
type Request ¶
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶
func NewRequestWithContext ¶
func (*Request) AddCookie ¶
AddCookie 添加cookie client CookieJar 默认不启用,如需使用 cookie ,先设置client 启用 CookieJar 只允许通过 client 设置,避免并发创建
func (*Request) AddCookies ¶
AddCookies 添加cookie client CookieJar 默认不启用,如需使用 cookie ,先设置client 启用 CookieJar 只允许通过 client 设置,避免并发创建
func (*Request) CustomRequest ¶
CustomRequest 自定义Request
func (*Request) KeepQueryParamOrder ¶
KeepQueryParamOrder 保持查询参数添加顺序
func (*Request) SetCheckProxy ¶
SetCheckProxy 设置代理检查函数
func (*Request) SetCheckRedirect ¶
func (r *Request) SetCheckRedirect(checkRedirect func(req *http.Request, via []*http.Request) error) *Request
SetCheckRedirect 设置该请求的重定向函数
func (*Request) SetFormData ¶
SetFormData 添加请求参数
func (*Request) SetJsonEscapeHTML ¶
SetJsonEscapeHTML 设置该请求json编码时是否转义HTML字符
func (*Request) SetJsonIndent ¶
SetJsonIndent 设置该请求json编码时的缩进格式 都为空不进行缩进
func (*Request) SetQueryParam ¶
SetQueryParam 添加URL path参数
func (*Request) SetQueryParams ¶
SetQueryParam 添加URL path参数
func (*Request) SetRawFormData ¶
SetRawFormData 添加请求参数
func (*Request) SetRawHead ¶
SetRawHead 设置head 不自动规范化
func (*Request) SetRawHeads ¶
SetRawHeads 设置head 不自动规范化
func (*Request) StringWithDecrypt ¶
func (r *Request) StringWithDecrypt(decrypt DecryptFunc) (statusCode int, resp string, err error)
func (*Request) UnmarshalWithDecrypt ¶
func (r *Request) UnmarshalWithDecrypt(decrypt DecryptFunc, val interface{}) (err error)
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
Response 请求结果
type TlsConnOption ¶
type TlsConnOption func(*Transport)
func WithHandShakeTimeout ¶
func WithHandShakeTimeout(handShakeTimeout time.Duration) TlsConnOption
func WithTcpDialTimeout ¶
func WithTcpDialTimeout(dialTimeout time.Duration) TlsConnOption
func WithTlsConnOptClientHelloID ¶
func WithTlsConnOptClientHelloID(id tls.ClientHelloID) TlsConnOption
func WithTlsConnOptClientHelloSpec ¶
func WithTlsConnOptClientHelloSpec(spec *tls.ClientHelloSpec) TlsConnOption
自定义tls指纹: HelloCustom + ClientHelloSpec
func WithTlsConnOptProxyAddr ¶
func WithTlsConnOptProxyAddr(proxyAddr string) TlsConnOption
type Transport ¶
type Transport struct { ProxyAddr string // "socks5://tst:ge5@127.0.0.1:8889" or "http://127.0.0.1:8888" ClientHelloSpec *tls.ClientHelloSpec // 仅当clientHelloID为HelloCustom时有用 ClientHelloID tls.ClientHelloID *Debug // 用于调试 // contains filtered or unexported fields }
包装http1和http2的transport 1. 通过底层的transport, 支持链接池管理 2. tls握手后自动选择http1.1或http2 3. 支持多线程访问
func NewTransport ¶
func NewTransport(opts ...TlsConnOption) *Transport
func (*Transport) SetH1Transport ¶
设置http1.1的transport模板,否则使用默认