Documentation ¶
Index ¶
- Variables
- func NewClient() *http.Client
- func NewTransport() *http.Transport
- func ProxyFromEnvironment(req *http.Request) (*url.URL, error)
- type Auth
- type MethodOption
- type Proxy
- type Request
- func (r *Request) CloseIdleConnections()
- func (r Request) Content() []byte
- func (r Request) ContentToString() string
- func (r *Request) Delete(originURL string, options ...MethodOption) error
- func (r *Request) Download(filePath, originURL string, rate int64) (int64, error)
- func (r *Request) DownloadToWriter(originURL string, w io.Writer) (int64, error)
- func (r *Request) Get(originURL string, options ...MethodOption) error
- func (r *Request) Post(originURL string, options ...MethodOption) error
- func (r *Request) Put(originURL string, options ...MethodOption) error
- func (r Request) Request() *http.Request
- func (r Request) Response() *http.Response
- func (r *Request) SetBasicAuth(username, password string)
- func (r *Request) SetBearerTokenAuth(token string)
- func (r *Request) SetClient(client *http.Client)
- func (r *Request) SetHeader(header map[string]string)
- func (r *Request) SetProxyEnv(proxy map[string]string)
- func (r *Request) SetProxyFunc(f func(*http.Request) (*url.URL, error))
- func (r *Request) SetProxyURL(proxy *url.URL)
- func (r *Request) SetSkipTLS()
- func (r *Request) SetTimeout(t time.Duration)
- func (r *Request) SetTransport(rt http.RoundTripper)
- func (r Request) Status() (int, string)
- func (r *Request) UnsetProxy()
- func (r *Request) Upload(originURL string, data map[string]string, rate int64, filePaths ...string) error
- type RequestOption
- func WithBasicAuth(username, password string) RequestOption
- func WithBearerTokenAuth(token string) RequestOption
- func WithClient(client *http.Client) RequestOption
- func WithDefaultClient() RequestOption
- func WithDefaultTransport() RequestOption
- func WithHeader(headers ...map[string]string) RequestOption
- func WithProxyEnv(proxy map[string]string) RequestOption
- func WithProxyFunc(f func(*http.Request) (*url.URL, error)) RequestOption
- func WithProxyURL(proxy *url.URL) RequestOption
- func WithSkipTLS() RequestOption
- func WithTimeout(t time.Duration) RequestOption
- func WithTransport(tr http.RoundTripper) RequestOption
- func WithUnsetProxy() RequestOption
- type RequestPool
- type SessionPool
Constants ¶
This section is empty.
Variables ¶
var ( // DefaultTransport is clone of http.DefaultTransport DefaultTransport = NewTransport() // DefaultClient set Transport to DefaultTransport DefaultClient = NewClient() )
Functions ¶
func NewTransport ¶ added in v1.2.12
NewTransport return clone of http.DefaultTransport
Types ¶
type MethodOption ¶ added in v1.3.1
type MethodOption func(r *Request)
func WithFormData ¶ added in v1.3.1
func WithFormData(data map[string]string) MethodOption
func WithJsonData ¶ added in v1.3.1
func WithJsonData(data map[string]any) MethodOption
func WithParams ¶ added in v1.3.1
func WithParams(params map[string]string) MethodOption
type Proxy ¶ added in v1.2.8
type Proxy struct {
// contains filtered or unexported fields
}
Proxy addr is host:port
func NewHttpProxy ¶ added in v1.2.8
func NewSocks5Proxy ¶ added in v1.3.1
func (*Proxy) ProxyRawURL ¶ added in v1.3.1
type Request ¶ added in v1.0.2
type Request struct {
// contains filtered or unexported fields
}
func NewRequest ¶ added in v1.0.2
func NewRequest(options ...RequestOption) *Request
NewRequest use DefaultClient to do http request, RequestOption can be provided to set Request properties
func NewSession ¶
func NewSession(options ...RequestOption) *Request
func (*Request) CloseIdleConnections ¶ added in v1.2.14
func (r *Request) CloseIdleConnections()
func (Request) ContentToString ¶ added in v1.1.0
func (*Request) Delete ¶ added in v1.0.3
func (r *Request) Delete(originURL string, options ...MethodOption) error
func (*Request) Download ¶ added in v1.0.7
Download rate is download speed per second, e.g. 1024 ==> 1KiB/s, 1024*1024 ==> 1MiB/s, if rate <= 0 it means no limit
func (*Request) DownloadToWriter ¶ added in v1.2.13
func (*Request) Get ¶ added in v1.0.2
func (r *Request) Get(originURL string, options ...MethodOption) error
func (*Request) Post ¶ added in v1.0.2
func (r *Request) Post(originURL string, options ...MethodOption) error
func (*Request) Put ¶ added in v1.0.3
func (r *Request) Put(originURL string, options ...MethodOption) error
func (*Request) SetBasicAuth ¶ added in v1.0.3
func (*Request) SetBearerTokenAuth ¶ added in v1.0.3
func (*Request) SetProxyEnv ¶ added in v1.2.12
func (*Request) SetProxyFunc ¶ added in v1.2.12
func (*Request) SetProxyURL ¶ added in v1.3.1
func (*Request) SetSkipTLS ¶ added in v1.2.12
func (r *Request) SetSkipTLS()
func (*Request) SetTimeout ¶ added in v1.0.3
func (*Request) SetTransport ¶ added in v1.2.3
func (r *Request) SetTransport(rt http.RoundTripper)
func (*Request) UnsetProxy ¶ added in v1.2.6
func (r *Request) UnsetProxy()
type RequestOption ¶ added in v1.3.1
type RequestOption func(*Request)
func WithBasicAuth ¶ added in v1.1.5
func WithBasicAuth(username, password string) RequestOption
func WithBearerTokenAuth ¶ added in v1.1.5
func WithBearerTokenAuth(token string) RequestOption
func WithClient ¶ added in v1.2.10
func WithClient(client *http.Client) RequestOption
func WithDefaultClient ¶ added in v1.2.10
func WithDefaultClient() RequestOption
func WithDefaultTransport ¶ added in v1.2.10
func WithDefaultTransport() RequestOption
func WithHeader ¶ added in v1.1.5
func WithHeader(headers ...map[string]string) RequestOption
func WithProxyEnv ¶ added in v1.2.12
func WithProxyEnv(proxy map[string]string) RequestOption
func WithProxyFunc ¶ added in v1.2.7
func WithProxyURL ¶ added in v1.3.1
func WithProxyURL(proxy *url.URL) RequestOption
func WithSkipTLS ¶ added in v1.2.12
func WithSkipTLS() RequestOption
func WithTimeout ¶ added in v1.1.5
func WithTimeout(t time.Duration) RequestOption
func WithTransport ¶ added in v1.2.4
func WithTransport(tr http.RoundTripper) RequestOption
func WithUnsetProxy ¶ added in v1.2.6
func WithUnsetProxy() RequestOption
type RequestPool ¶ added in v1.3.0
type RequestPool struct {
// contains filtered or unexported fields
}
RequestPool both RequestPool and SessionPool use sync.Pool to cache and reuse Request when you want to do bulk http requests with separate http.Client, default use WithClient(NewClient) RequestOption when creating pool RequestOption can be provided to Get to set Request properties, don't forget to call Put when http request done
func NewRequestPool ¶ added in v1.3.0
func NewRequestPool() *RequestPool
func (*RequestPool) Get ¶ added in v1.3.0
func (rp *RequestPool) Get(options ...RequestOption) *Request
func (*RequestPool) Put ¶ added in v1.3.0
func (rp *RequestPool) Put(r *Request)
Put to avoid connection leaks, call CloseIdleConnections before put back to pool
type SessionPool ¶ added in v1.3.0
type SessionPool struct {
*RequestPool
}
func NewSessionPool ¶ added in v1.3.0
func NewSessionPool(options ...RequestOption) *SessionPool