Documentation ¶
Index ¶
- Variables
- func CreateReqCtx(ctx context.Context, option *RequestOption) context.Context
- func NewDialer(option DialOption) *net.Dialer
- func NewJar() *jar
- func NewRequestWithContext(ctx context.Context, method string, u *url.URL, body io.Reader) (*http.Request, error)
- type Client
- func (obj *Client) ClearCookies()
- func (obj *Client) Close()
- func (obj *Client) CloseConns()
- func (obj *Client) Connect(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Delete(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) ForceCloseConns()
- func (obj *Client) Get(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) GetCookies(href *url.URL) Cookies
- func (obj *Client) Head(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Options(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Patch(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Post(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Put(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- func (obj *Client) Request(ctx context.Context, method string, href string, options ...RequestOption) (response *Response, err error)
- func (obj *Client) SetCookies(href *url.URL, cookies ...any) error
- func (obj *Client) SetGetProxy(getProxy func(ctx context.Context, url *url.URL) (string, error))
- func (obj *Client) SetGetProxys(getProxys func(ctx context.Context, url *url.URL) ([]string, error))
- func (obj *Client) SetProxy(proxyUrl string) (err error)
- func (obj *Client) SetProxys(proxyUrls []string) (err error)
- func (obj *Client) Trace(ctx context.Context, href string, options ...RequestOption) (*Response, error)
- type ClientOption
- type Conn
- type Cookies
- type DialClient
- func (obj *DialClient) DialContext(ctx context.Context, ctxData *RequestOption, network string, addr string) (net.Conn, error)
- func (obj *DialClient) DialProxyContext(ctx context.Context, ctxData *RequestOption, network string, ...) (net.Conn, error)
- func (obj *DialClient) ProxyDialContext(ctx context.Context, ctxData *RequestOption, network string, addr string) (net.Conn, error)
- func (obj *DialClient) Socks5Proxy(ctx context.Context, ctxData *RequestOption, network string, proxyUrl *url.URL, ...) (conn net.Conn, err error)
- type DialOption
- type Event
- type File
- type Jar
- type Log
- type LogType
- type OrderMap
- type RequestOption
- type Response
- func Connect(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Delete(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Get(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Head(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Options(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Patch(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Post(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Put(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func Request(ctx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
- func Trace(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
- func (obj *Response) Body() io.ReadCloser
- func (obj *Response) CloseBody()
- func (obj *Response) CloseConn()
- func (obj *Response) Content() []byte
- func (obj *Response) ContentEncoding() string
- func (obj *Response) ContentLength() int64
- func (obj *Response) ContentType() string
- func (obj *Response) Cookies() Cookies
- func (obj *Response) Decode(encoding string)
- func (obj *Response) ForceCloseConn()
- func (obj *Response) Headers() http.Header
- func (obj *Response) Html() *bs4.Client
- func (obj *Response) IsNewConn() bool
- func (obj *Response) IsSSE() bool
- func (obj *Response) IsStream() bool
- func (obj *Response) IsWebSocket() bool
- func (obj *Response) Json(vals ...any) (*gson.Client, error)
- func (obj *Response) Location() (*url.URL, error)
- func (obj *Response) Map() (data map[string]any, err error)
- func (obj *Response) Proto() string
- func (obj *Response) Proxys() []*url.URL
- func (obj *Response) ReadBody() (err error)
- func (obj *Response) SSE() *SSE
- func (obj *Response) SetContent(val []byte)
- func (obj *Response) Status() string
- func (obj *Response) StatusCode() int
- func (obj *Response) Text() string
- func (obj *Response) Url() *url.URL
- func (obj *Response) WebSocket() *websocket.Conn
- type SSE
Constants ¶
This section is empty.
Variables ¶
var ErrUseLastResponse = http.ErrUseLastResponse
Functions ¶
func CreateReqCtx ¶
func CreateReqCtx(ctx context.Context, option *RequestOption) context.Context
func NewDialer ¶
func NewDialer(option DialOption) *net.Dialer
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Connection Management
func NewClient ¶
func NewClient(preCtx context.Context, options ...ClientOption) (*Client, error)
New Connection Management
func (*Client) Close ¶
func (obj *Client) Close()
Close the client and cannot be used again after shutdown
func (*Client) CloseConns ¶
func (obj *Client) CloseConns()
Close idle connections. If the connection is in use, wait until it ends before closing
func (*Client) Connect ¶
func (obj *Client) Connect(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Connect request and returns the response.
func (*Client) Delete ¶
func (obj *Client) Delete(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Delete request and returns the response.
func (*Client) ForceCloseConns ¶
func (obj *Client) ForceCloseConns()
Close the connection, even if it is in use, it will be closed
func (*Client) Get ¶
func (obj *Client) Get(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Get request and returns the response.
func (*Client) Head ¶
func (obj *Client) Head(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Head request and returns the response.
func (*Client) Options ¶
func (obj *Client) Options(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Options request and returns the response.
func (*Client) Patch ¶
func (obj *Client) Patch(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Patch request and returns the response.
func (*Client) Post ¶
func (obj *Client) Post(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Post request and returns the response.
func (*Client) Put ¶
func (obj *Client) Put(ctx context.Context, href string, options ...RequestOption) (*Response, error)
sends a Put request and returns the response.
func (*Client) Request ¶
func (obj *Client) Request(ctx context.Context, method string, href string, options ...RequestOption) (response *Response, err error)
Define a function named Request that takes in four parameters:
func (*Client) SetCookies ¶
set cookies
func (*Client) SetGetProxy ¶
Modify the proxy method of the client
func (*Client) SetGetProxys ¶
func (obj *Client) SetGetProxys(getProxys func(ctx context.Context, url *url.URL) ([]string, error))
Modify the proxy method of the client
type ClientOption ¶
type ClientOption struct { Logger func(Log) //debuggable H3 bool //开启http3 OrderHeaders []string //order headers Ja3Spec ja3.Ja3Spec //custom ja3Spec,use ja3.CreateSpecWithStr or ja3.CreateSpecWithId create H2Ja3Spec ja3.H2Ja3Spec //h2 fingerprint Proxy string //proxy,support https,http,socks5 Proxys []string //proxy list,support https,http,socks5 ForceHttp1 bool //force use http1 send requests Ja3 bool //enable ja3 fingerprint DisCookie bool //disable cookies DisDecode bool //disable auto decode DisUnZip bool //disable auto zip decode DisAlive bool //disable keepalive Bar bool ////enable bar display OptionCallBack func(ctx context.Context, option *RequestOption) error //option callback,if error is returnd, break request ResultCallBack func(ctx context.Context, option *RequestOption, response *Response) error //result callback,if error is returnd,next errCallback ErrCallBack func(ctx context.Context, option *RequestOption, response *Response, err error) error //error callback,if error is returnd,break request RequestCallBack func(ctx context.Context, request *http.Request, response *http.Response) error //request and response callback,if error is returnd,reponse is error MaxRetries int //try num MaxRedirect int //redirect num ,<0 no redirect,==0 no limit Headers any //default headers Timeout time.Duration //request timeout ResponseHeaderTimeout time.Duration //ResponseHeaderTimeout ,default:300 TlsHandshakeTimeout time.Duration //tls timeout,default:15 UserAgent string //headers User-Agent value //other option GetProxy func(ctx context.Context, url *url.URL) (string, error) //proxy callback:support https,http,socks5 proxy GetProxys func(ctx context.Context, url *url.URL) ([]string, error) //proxys callback:support https,http,socks5 proxy GetAddrType func(host string) gtls.AddrType //network card ip DialTimeout time.Duration //dial tcp timeout,default:15 KeepAlive time.Duration //keepalive,default:30 LocalAddr *net.TCPAddr Dns *net.UDPAddr //dns AddrType gtls.AddrType //dns parse addr type Jar Jar //custom cookies TlsConfig *tls.Config UtlsConfig *utls.Config }
Connection Management Options
type Cookies ¶
cookies
func ReadCookies ¶
read cookies or parse cookies,support json,map,[]string,http.Header,string
type DialClient ¶
type DialClient struct {
// contains filtered or unexported fields
}
func NewDail ¶
func NewDail(option DialOption) *DialClient
func (*DialClient) DialContext ¶
func (obj *DialClient) DialContext(ctx context.Context, ctxData *RequestOption, network string, addr string) (net.Conn, error)
func (*DialClient) DialProxyContext ¶
func (*DialClient) ProxyDialContext ¶
func (obj *DialClient) ProxyDialContext(ctx context.Context, ctxData *RequestOption, network string, addr string) (net.Conn, error)
func (*DialClient) Socks5Proxy ¶
type DialOption ¶
type LogType ¶
type LogType string
const ( LogType_DNSLookup LogType = "DNSLookup" LogType_TCPConnect LogType = "TCPConnect" LogType_TLSHandshake LogType = "TLSHandshake" LogType_ProxyDNSLookup LogType = "ProxyDNSLookup" LogType_ProxyTCPConnect LogType = "ProxyTCPConnect" LogType_ProxyTLSHandshake LogType = "ProxyTLSHandshake" LogType_ProxyConnectRemote LogType = "ProxyConnectRemote" LogType_ResponseHeader LogType = "ResponseHeader" LogType_ResponseBody LogType = "ResponseBody" )
type OrderMap ¶
type OrderMap struct {
// contains filtered or unexported fields
}
func NewOrderMap ¶
func NewOrderMap() *OrderMap
func (*OrderMap) MarshalJSON ¶
type RequestOption ¶
type RequestOption struct { Logger func(Log) //debuggable H3 bool //开启http3 OrderHeaders []string //order headers Ja3Spec ja3.Ja3Spec //custom ja3Spec,use ja3.CreateSpecWithStr or ja3.CreateSpecWithId create H2Ja3Spec ja3.H2Ja3Spec //custom h2 fingerprint Proxy string //proxy,support http,https,socks5,example:http://127.0.0.1:7005 Proxys []string //proxy list,support http,https,socks5,example:http://127.0.0.1:7005 ForceHttp1 bool //force use http1 send requests Ja3 bool //enable ja3 fingerprint DisCookie bool //disable cookies,not use cookies DisDecode bool //disable auto decode DisUnZip bool //disable auto zip decode Bar bool //enable bar display OptionCallBack func(ctx context.Context, option *RequestOption) error //option callback,if error is returnd, break request ResultCallBack func(ctx context.Context, option *RequestOption, response *Response) error //result callback,if error is returnd,next errCallback ErrCallBack func(ctx context.Context, option *RequestOption, response *Response, err error) error //error callback,if error is returnd,break request RequestCallBack func(ctx context.Context, request *http.Request, response *http.Response) error //request and response callback,if error is returnd,reponse is error MaxRetries int //try num MaxRedirect int //redirect num ,<0 no redirect,==0 no limit Headers any //request headers:json,map,header Timeout time.Duration //request timeout ResponseHeaderTimeout time.Duration //ResponseHeaderTimeout ,default:300 TlsHandshakeTimeout time.Duration UserAgent string //headers User-Agent value GetProxy func(ctx context.Context, url *url.URL) (string, error) //proxy callback:support https,http,socks5 proxy GetProxys func(ctx context.Context, url *url.URL) ([]string, error) //proxys callback:support https,http,socks5 proxy GetAddrType func(host string) gtls.AddrType //network card ip DialTimeout time.Duration //dial tcp timeout,default:15 KeepAlive time.Duration //keepalive,default:30 LocalAddr *net.TCPAddr Dns *net.UDPAddr //dns AddrType gtls.AddrType //dns parse addr type //tls timeout,default:15 Jar Jar //custom cookies TlsConfig *tls.Config UtlsConfig *utls.Config // other option Method string //method Url *url.URL Host string Referer string //set headers referer value ContentType string //headers Content-Type value Cookies any // cookies,support :json,map,str,http.Header Params any //url params,join url query,json,map Json any //send application/json,support io.Reader,:string,[]bytes,json,map Data any //send application/x-www-form-urlencoded, support io.Reader, string,[]bytes,json,map Form any //send multipart/form-data,file upload,support io.Reader, json,map Text any //send text/xml,support: io.Reader, string,[]bytes,json,map Body any //not setting context-type,support io.Reader, string,[]bytes,json,map Stream bool //disable auto read WsOption websocket.Option //websocket option DisProxy bool //force disable proxy // contains filtered or unexported fields }
Options for sending requests
func GetRequestOption ¶
func GetRequestOption(ctx context.Context) *RequestOption
func (*RequestOption) Client ¶
func (obj *RequestOption) Client() *Client
type Response ¶
type Response struct {
// contains filtered or unexported fields
}
func Connect ¶
func Connect(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
sends a Connect request and returns the response.
func Options ¶
func Options(ctx context.Context, href string, options ...RequestOption) (resp *Response, err error)
sends a Options request and returns the response.
func Request ¶
func Request(ctx context.Context, method string, href string, options ...RequestOption) (resp *Response, err error)
Define a function named Request that takes in four parameters:
func (*Response) Body ¶
func (obj *Response) Body() io.ReadCloser
func (*Response) ContentEncoding ¶
return content encoding
func (*Response) IsWebSocket ¶
return true if response is other stream
func (*Response) SetContent ¶
set response content with []byte