Documentation ¶
Index ¶
- Constants
- func GetFreePort() int
- type Client
- func NewClient(options *ClientOptions, jar *cookiejar.Jar) (*Client, error)
- func NewDefaultClient(jar *cookiejar.Jar) (*Client, error)
- func NewDefaultRedirectClient(jar *cookiejar.Jar) (*Client, error)
- func NewRedirectClient(options *ClientOptions, jar *cookiejar.Jar) (*Client, error)
- func NewWithHTTPClient(options *ClientOptions, hc *http.Client) (*Client, error)
- func (c *Client) AfterResponse(fn ResponseMiddleware)
- func (c *Client) BeforeRequest(fn RequestMiddleware)
- func (c *Client) Do(ctx context.Context, req *Request) (*Response, error)
- func (c *Client) SetCloseConnection(close bool) *Client
- func (c *Client) WithRedirect(redirect bool) *Client
- func (c *Client) WithoutCookieJar() *Client
- type ClientOptions
- type Request
- func (r *Request) Clone() *Request
- func (r *Request) EnableTrace() *Request
- func (r *Request) FuzzCommonHeaders(value string)
- func (r *Request) GetAttempt() int
- func (r *Request) GetBody() ([]byte, error)
- func (r *Request) GetContentType() string
- func (r *Request) GetContext() context.Context
- func (r *Request) GetFragment() string
- func (r *Request) GetHeaders() http.Header
- func (r *Request) GetHost() string
- func (r *Request) GetHostName() string
- func (r *Request) GetMethod() string
- func (r *Request) GetPath() string
- func (r *Request) GetPort() string
- func (r *Request) GetQuery() string
- func (r *Request) GetRaw() ([]byte, error)
- func (r *Request) GetScheme() string
- func (r *Request) GetUrl() *url.URL
- func (r *Request) SetBody(body []byte) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetCookie(hc *http.Cookie) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaderMulti(headers map[string]string) *Request
- func (r *Request) SetHeaderMultiValues(headers map[string][]string) *Request
- func (r *Request) SetHeaders(headers map[string]string) *Request
- type RequestMiddleware
- type Response
- type ResponseMiddleware
- type TraceInfo
Constants ¶
const ( // MethodGet HTTP method MethodGet = "GET" // MethodPost HTTP method MethodPost = "POST" // MethodPut HTTP method MethodPut = "PUT" // MethodDelete HTTP method MethodDelete = "DELETE" // MethodPatch HTTP method MethodPatch = "PATCH" // MethodHead HTTP method MethodHead = "HEAD" // MethodOptions HTTP method MethodOptions = "OPTIONS" // MethodConnect HTTP method MethodConnect = "CONNECT" // MethodTrace HTTP method MethodTrace = "TRACE" // MethodMove HTTP method MethodMove = "MOVE" // MethodPURGE MethodMove HTTP method MethodPURGE = "PURGE" )
Variables ¶
This section is empty.
Functions ¶
func GetFreePort ¶
func GetFreePort() int
Types ¶
type Client ¶
type Client struct { HTTPClient *http.Client ClientOptions *ClientOptions Debug bool // if debug == true, start responseLogger middleware Error interface{} // todo error handle exp // handle LocalAddress *net.TCPAddr // contains filtered or unexported fields }
Client struct
func NewClient ¶
func NewClient(options *ClientOptions, jar *cookiejar.Jar) (*Client, error)
NewClient xhttp.Client
func NewDefaultClient ¶
NewDefaultClient xhttp.Client not follow redirect
func NewDefaultRedirectClient ¶
NewDefaultRedirectClient follow redirect
func NewRedirectClient ¶
func NewRedirectClient(options *ClientOptions, jar *cookiejar.Jar) (*Client, error)
NewRedirectClient xhttp.Client with Redirect
func NewWithHTTPClient ¶
func NewWithHTTPClient(options *ClientOptions, hc *http.Client) (*Client, error)
NewWithHTTPClient with http client
func (*Client) AfterResponse ¶
func (c *Client) AfterResponse(fn ResponseMiddleware)
func (*Client) BeforeRequest ¶
func (c *Client) BeforeRequest(fn RequestMiddleware)
func (*Client) SetCloseConnection ¶
func (*Client) WithRedirect ¶
func (*Client) WithoutCookieJar ¶
type ClientOptions ¶
type ClientOptions struct { Proxy string `` /* 164-byte string literal not displayed */ //ProxyRule []Rule `json:"proxy_rule" yaml:"proxy_rule" #:"漏洞扫描使用多个代理的配置规则, 具体请参照文档"` DialTimeout int `json:"dial_timeout" yaml:"dial_timeout" #:"建立 tcp 连接的超时时间"` ReadTimeout int `` /* 137-byte string literal not displayed */ MaxConnsPerHost int `` /* 136-byte string literal not displayed */ EnableHTTP2 bool `` /* 141-byte string literal not displayed */ IdleConnTimeout int `json:"-" yaml:"-"` MaxIdleConns int `json:"-" yaml:"-"` TLSHandshakeTimeout int `json:"-" yaml:"-"` FailRetries int `json:"fail_retries" yaml:"fail_retries" #:"请求失败的重试次数, 0 则不重试"` MaxRedirect int `json:"max_redirect" yaml:"max_redirect" #:"单个请求最大允许的跳转数"` MaxRespBodySize int64 `json:"max_resp_body_size" yaml:"max_resp_body_size" #:"最大允许的响应大小, 默认 4M"` MaxQPS int `json:"max_qps" yaml:"max_qps" #:"每秒最大请求数"` AllowMethods []string `json:"allow_methods" yaml:"allow_methods" #:"允许的请求方法"` Headers map[string]string `json:"headers" yaml:"headers" #:"自定义 headers"` Cookies map[string]string `json:"cookies" yaml:"cookies" #:"自定义 cookies, 参考 headers 格式, key: value"` TlsOptions *xtls.ClientOptions `json:"tls" yaml:"tls" #:"tls 配置"` Debug bool `json:"http_debug" yaml:"http_debug" #:"是否启用 debug 模式, 开启 request trace"` DisableKeepAlives bool `json:"disable_keep_alives" yaml:"disable_keep_alives" #:"是否禁用 keepalives"` Limiter *rate.Limiter `json:"-" yaml:"-"` SoloConn bool `json:"solo_conn" yaml:"solo_conn" #:"是否启用单连接模式"` }
ClientOptions http client options
func DefaultClientOptions ¶
func DefaultClientOptions() *ClientOptions
func (*ClientOptions) Clone ¶
func (o *ClientOptions) Clone() *ClientOptions
Clone 这里的 Limiter 没有被 Clone,todo: Limiter 不应该放在 options,而是 client 里
func (*ClientOptions) SetLimiter ¶
func (o *ClientOptions) SetLimiter() *ClientOptions
func (*ClientOptions) Verify ¶
func (o *ClientOptions) Verify() error
type Request ¶
type Request struct { RawRequest *http.Request Error interface{} Body []byte // contains filtered or unexported fields }
func (*Request) EnableTrace ¶
func (*Request) FuzzCommonHeaders ¶
func (*Request) GetContentType ¶
func (*Request) GetFragment ¶
func (*Request) GetHeaders ¶
func (*Request) GetHostName ¶
func (*Request) SetContext ¶
SetContext set
func (*Request) SetHeader ¶
SetHeader set a single header field and its value in the current request
func (*Request) SetHeaderMulti ¶
func (*Request) SetHeaderMultiValues ¶
SetHeaderMultiValues sets multiple headers fields and its values is list of strings For Example: To set `Accept` as `text/html, application/xhtml+xml, application/xml;q=0.9, image/webp, */*;q=0.8`
type RequestMiddleware ¶
RequestMiddleware run before request
type Response ¶
type Response struct { Request *Request RawResponse *http.Response Body []byte // contains filtered or unexported fields }
func (*Response) GetContentType ¶
func (*Response) GetHeaders ¶
type ResponseMiddleware ¶
ResponseMiddleware run after receive response
type TraceInfo ¶
type TraceInfo struct { // DNSLookup is a duration that transport took to perform DNSLookup time.Duration // ConnTime is a duration that took to obtain a successful connection. ConnTime time.Duration // TCPConnTime is a duration that took to obtain the TCP connection. TCPConnTime time.Duration // TLSHandshake is a duration that TLS handshake took place. TLSHandshake time.Duration // ServerTime is a duration that server took to respond first byte. ServerTime time.Duration // ResponseTime is a duration since first response byte from server to // request completion. ResponseTime time.Duration // TotalTime is a duration that total request took end-to-end. TotalTime time.Duration // IsConnReused is whether this connection has been previously // used for another HTTP request. IsConnReused bool // IsConnWasIdle is whether this connection was obtained from an // idle pool. IsConnWasIdle bool // ConnIdleTime is a duration how long the connection was previously // idle, if IsConnWasIdle is true. ConnIdleTime time.Duration // RequestAttempt is to represent the request attempt made during a Resty // request execution flow, including retry count. //RequestAttempt int // RemoteAddr returns the remote network address. RemoteAddr net.Addr }