Client
Create Request
These methods of Client
will create a new Request
:
- R()
- NewRequest() - Alias of R.
- Get(url …string) - Create request with GET method, URL is optional.
- Post(url …string)
- Head(url …string)
- Delete(url …string)
- Put(url …string)
- Patch(url …string)
- Options(url …string)
Create Parallel Download
- NewParallelDownload(url string) - Parallel download.
Client Settings
The following are the chainable settings of Client, all of which have corresponding global wrappers (Just treat the package name req
as a Client to test, set up the Client without create any Client explicitly).
Basically, you can know the meaning of most settings directly from the method name.
Debug Features
- DevMode() - Enable all debug features (Dump, DebugLog and Trace).
- EnableDebugLog() - Enable debug level log (disabled by default).
- DisableDebugLog()
- SetLogger(log Logger) - Set the customized logger.
- EnableTraceAll() - Enable trace for all requests (disabled by default).
- DisableTraceAll()
- EnableDumpAll() - Enable dump for all requests.
- DisableDumpAll()
- SetCommonDumpOptions(opt *DumpOptions)
- EnableDumpAllAsync()
- EnableDumpAllTo(output io.Writer)
- EnableDumpAllToFile(filename string)
- EnableDumpAllWithoutBody()
- EnableDumpAllWithoutHeader()
- EnableDumpAllWithoutRequest()
- EnableDumpAllWithoutRequestBody()
- EnableDumpAllWithoutResponse()
- EnableDumpAllWithoutResponseBody()
- EnableDumpEeachRequest() - syntax sugar, use request middleware to enable dump separately for each request (without printing), and get dump content when needed.
- EnableDumpEeachRequestWithoutBody()
- EnableDumpEeachRequestWithoutHeader()
- EnableDumpEeachRequestWithoutResponse()
- EnableDumpEeachRequestWithoutRequest()
- EnableDumpEeachRequestWithoutRequestBody()
- EnableDumpEeachRequestWithoutResponseBody()
Common Settings for constructing HTTP Requests
- SetCommonBasicAuth(username, password string)
- SetCommonBearerAuthToken(token string)
- SetCommonDigestAuth(username, password string)
- SetCommonContentType(ct string)
- SetCommonCookies(cookies …*http.Cookie)
- SetCommonFormData(data map[string]string)
- SetCommonFormDataFromValues(data url.Values)
- SetCommonHeader(key, value string)
- SetCommonHeaders(hdrs map[string]string)
- SetCommonHeaderOrder(keys …string)
- SetCommonPseudoHeaderOder(keys …string)
- SetCommonPathParam(key, value string)
- SetCommonPathParams(pathParams map[string]string)
- SetCommonQueryParam(key, value string)
- SetCommonQueryParams(params map[string]string)
- SetCommonQueryString(query string)
- AddCommonQueryParam(key, value string)
- SetUserAgent(userAgent string)
- SetCommonErrorResult(err interface{})
Auto-Decode
- EnableAutoDecode() - Enabled by default, auto-detect charset and decode to utf-8
- DisableAutoDecode()
- SetAutoDecodeContentType(contentTypes …string)
- SetAutoDecodeAllContentType()
- SetAutoDecodeContentTypeFunc(fn func(contentType string) bool)
TLS and Certificates
- SetCerts(certs …tls.Certificate)
- SetCertFromFile(certFile, keyFile string)
- SetRootCertsFromFile(pemFiles …string)
- SetRootCertFromString(pemContent string)
- EnableInsecureSkipVerify()
- DisableInsecureSkipVerify - Disabled by default.
- SetTLSHandshakeTimeout(timeout time.Duration)
- SetTLSClientConfig(conf *tls.Config)
- SetTLSFingerprintChrome()
- SetTLSFingerprintFirefox()
- SetTLSFingerprintEdge()
- SetTLSFingerprintQQ()
- SetTLSFingerprintSafari()
- SetTLSFingerprint360()
- SetTLSFingerprintIOS()
- SetTLSFingerprintAndroid()
- SetTLSFingerprintRandomized()
Marshal&Unmarshal
- SetJsonUnmarshal(fn func(data []byte, v interface{}) error)
- SetJsonMarshal(fn func(v interface{}) ([]byte, error))
- SetXmlUnmarshal(fn func(data []byte, v interface{}) error)
- SetXmlMarshal(fn func(v interface{}) ([]byte, error))
Middleware
HTTP Version
Retry
- SetCommonRetryCount(count int)
- SetCommonRetryInterval(getRetryIntervalFunc GetRetryIntervalFunc)
- SetCommonRetryFixedInterval(interval time.Duration)
- SetCommonRetryBackoffInterval(min, max time.Duration)
- SetCommonRetryHook(hook RetryHookFunc)
- AddCommonRetryHook(hook RetryHookFunc)
- SetCommonRetryCondition(condition RetryConditionFunc)
- AddCommonRetryCondition(condition RetryConditionFunc)
Middleware
- WrapRoundTripFunc(funcs …RoundTripWrapperFunc) - Client Middleware
- WrapRoundTrip(wrappers …RoundTripWrapper) - Client Middleware
- OnBeforeRequest(m RequestMiddleware) - Request Middleware
- OnAfterResponse(m ResponseMiddleware) - Response Middleware
Network, Proxy And URL
- SetTimeout(d time.Duration)
- SetDialTLS(fn func(ctx context.Context, network, addr string) (net.Conn, error))
- SetDial(fn func(ctx context.Context, network, addr string) (net.Conn, error))
- SetProxyURL(proxyUrl string)
- SetProxy(proxy func(*http.Request) (*urlpkg.URL, error))
- SetUnixSocket(file string)
- SetScheme(scheme string)
- SetBaseURL(u string)
H2C
- EnableH2C() - Disabled by default.
- DisableH2C()
Keepalive, Cookie, Compression and Redirect Policy
- EnableKeepAlives() - Enabled by default.
- DisableKeepAlives()
- SetCookieJar(jar http.CookieJar)
- ClearCookies()
- EnableCompression() - Enabled by default.
- DisableCompression()
- SetRedirectPolicy(policies …RedirectPolicy)
Download, Auto-Read Response and Allow Get Method Payload
- SetOutputDirectory(dir string) - Download directory.
- EnableAutoReadResponse() - Enabled by default
- DisableAutoReadResponse()
- EnableAllowGetMethodPayload() - Enabled by default
- DisableAllowGetMethodPayload()