Documentation ¶
Index ¶
- Variables
- func CanonicalMIMEHeaderKey(s string) string
- func SetDefaultClient(c *Client)
- type Client
- func AddCommonQueryParam(key, value string) *Client
- func C() *Client
- func DefaultClient() *Client
- func DevMode() *Client
- func DisableAllowGetMethodPayload() *Client
- func DisableAutoDecode() *Client
- func DisableAutoReadResponse() *Client
- func DisableCompression() *Client
- func DisableDebugLog() *Client
- func DisableDumpAll() *Client
- func DisableForceHTTP1() *Client
- func DisableKeepAlives() *Client
- func DisableTraceAll() *Client
- func EnableAllowGetMethodPayload() *Client
- func EnableAutoDecode() *Client
- func EnableAutoReadResponse() *Client
- func EnableCompression() *Client
- func EnableDebugLog() *Client
- func EnableDumpAll() *Client
- func EnableDumpAllAsync() *Client
- func EnableDumpAllTo(output io.Writer) *Client
- func EnableDumpAllToFile(filename string) *Client
- func EnableDumpAllWithoutBody() *Client
- func EnableDumpAllWithoutHeader() *Client
- func EnableDumpAllWithoutRequest() *Client
- func EnableDumpAllWithoutRequestBody() *Client
- func EnableDumpAllWithoutResponse() *Client
- func EnableDumpAllWithoutResponseBody() *Client
- func EnableForceHTTP1() *Client
- func EnableKeepAlives() *Client
- func EnableTraceAll() *Client
- func NewClient() *Client
- func OnAfterResponse(m ResponseMiddleware) *Client
- func OnBeforeRequest(m RequestMiddleware) *Client
- func SetAutoDecodeAllType() *Client
- func SetAutoDecodeAllTypeFunc(fn func(contentType string) bool) *Client
- func SetAutoDecodeContentType(contentTypes ...string) *Client
- func SetBaseURL(u string) *Client
- func SetCertFromFile(certFile, keyFile string) *Client
- func SetCerts(certs ...tls.Certificate) *Client
- func SetCommonBasicAuth(username, password string) *Client
- func SetCommonBearerAuthToken(token string) *Client
- func SetCommonContentType(ct string) *Client
- func SetCommonCookies(cookies ...*http.Cookie) *Client
- func SetCommonDumpOptions(opt *DumpOptions) *Client
- func SetCommonFormData(data map[string]string) *Client
- func SetCommonFormDataFromValues(data urlpkg.Values) *Client
- func SetCommonHeader(key, value string) *Client
- func SetCommonHeaders(hdrs map[string]string) *Client
- func SetCommonQueryParam(key, value string) *Client
- func SetCommonQueryParams(params map[string]string) *Client
- func SetCommonQueryString(query string) *Client
- func SetCookieJar(jar http.CookieJar) *Client
- func SetDial(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
- func SetDialTLS(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
- func SetJsonMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func SetJsonUnmarshal(fn func(data []byte, v interface{}) error) *Client
- func SetLogger(log Logger) *Client
- func SetOutputDirectory(dir string) *Client
- func SetProxy(proxy func(*http.Request) (*urlpkg.URL, error)) *Client
- func SetProxyURL(proxyUrl string) *Client
- func SetRedirectPolicy(policies ...RedirectPolicy) *Client
- func SetRootCertFromString(pemContent string) *Client
- func SetRootCertsFromFile(pemFiles ...string) *Client
- func SetScheme(scheme string) *Client
- func SetTLSClientConfig(conf *tls.Config) *Client
- func SetTLSHandshakeTimeout(timeout time.Duration) *Client
- func SetTimeout(d time.Duration) *Client
- func SetUserAgent(userAgent string) *Client
- func SetXmlMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func SetXmlUnmarshal(fn func(data []byte, v interface{}) error) *Client
- func (c *Client) AddCommonQueryParam(key, value string) *Client
- func (c *Client) Clone() *Client
- func (c *Client) DevMode() *Client
- func (c *Client) DisableAllowGetMethodPayload() *Client
- func (c *Client) DisableAutoDecode() *Client
- func (c *Client) DisableAutoReadResponse() *Client
- func (c *Client) DisableCompression() *Client
- func (c *Client) DisableDebugLog() *Client
- func (c *Client) DisableDumpAll() *Client
- func (c *Client) DisableForceHTTP1() *Client
- func (c *Client) DisableKeepAlives() *Client
- func (c *Client) DisableTraceAll() *Client
- func (c *Client) EnableAllowGetMethodPayload() *Client
- func (c *Client) EnableAutoDecode() *Client
- func (c *Client) EnableAutoReadResponse() *Client
- func (c *Client) EnableCompression() *Client
- func (c *Client) EnableDebugLog() *Client
- func (c *Client) EnableDumpAll() *Client
- func (c *Client) EnableDumpAllAsync() *Client
- func (c *Client) EnableDumpAllTo(output io.Writer) *Client
- func (c *Client) EnableDumpAllToFile(filename string) *Client
- func (c *Client) EnableDumpAllWithoutBody() *Client
- func (c *Client) EnableDumpAllWithoutHeader() *Client
- func (c *Client) EnableDumpAllWithoutRequest() *Client
- func (c *Client) EnableDumpAllWithoutRequestBody() *Client
- func (c *Client) EnableDumpAllWithoutResponse() *Client
- func (c *Client) EnableDumpAllWithoutResponseBody() *Client
- func (c *Client) EnableForceHTTP1() *Client
- func (c *Client) EnableKeepAlives() *Client
- func (c *Client) EnableTraceAll() *Client
- func (c *Client) NewRequest() *Request
- func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client
- func (c *Client) OnBeforeRequest(m RequestMiddleware) *Client
- func (c *Client) R() *Request
- func (c *Client) SetAutoDecodeAllType() *Client
- func (c *Client) SetAutoDecodeAllTypeFunc(fn func(contentType string) bool) *Client
- func (c *Client) SetAutoDecodeContentType(contentTypes ...string) *Client
- func (c *Client) SetBaseURL(u string) *Client
- func (c *Client) SetCertFromFile(certFile, keyFile string) *Client
- func (c *Client) SetCerts(certs ...tls.Certificate) *Client
- func (c *Client) SetCommonBasicAuth(username, password string) *Client
- func (c *Client) SetCommonBearerAuthToken(token string) *Client
- func (c *Client) SetCommonContentType(ct string) *Client
- func (c *Client) SetCommonCookies(cookies ...*http.Cookie) *Client
- func (c *Client) SetCommonDumpOptions(opt *DumpOptions) *Client
- func (c *Client) SetCommonFormData(data map[string]string) *Client
- func (c *Client) SetCommonFormDataFromValues(data urlpkg.Values) *Client
- func (c *Client) SetCommonHeader(key, value string) *Client
- func (c *Client) SetCommonHeaders(hdrs map[string]string) *Client
- func (c *Client) SetCommonQueryParam(key, value string) *Client
- func (c *Client) SetCommonQueryParams(params map[string]string) *Client
- func (c *Client) SetCommonQueryString(query string) *Client
- func (c *Client) SetCookieJar(jar http.CookieJar) *Client
- func (c *Client) SetDial(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
- func (c *Client) SetDialTLS(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
- func (c *Client) SetJsonMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func (c *Client) SetJsonUnmarshal(fn func(data []byte, v interface{}) error) *Client
- func (c *Client) SetLogger(log Logger) *Client
- func (c *Client) SetOutputDirectory(dir string) *Client
- func (c *Client) SetProxy(proxy func(*http.Request) (*urlpkg.URL, error)) *Client
- func (c *Client) SetProxyURL(proxyUrl string) *Client
- func (c *Client) SetRedirectPolicy(policies ...RedirectPolicy) *Client
- func (c *Client) SetRootCertFromString(pemContent string) *Client
- func (c *Client) SetRootCertsFromFile(pemFiles ...string) *Client
- func (c *Client) SetScheme(scheme string) *Client
- func (c *Client) SetTLSClientConfig(conf *tls.Config) *Client
- func (c *Client) SetTLSHandshakeTimeout(timeout time.Duration) *Client
- func (c *Client) SetTimeout(d time.Duration) *Client
- func (c *Client) SetUserAgent(userAgent string) *Client
- func (c *Client) SetXmlMarshal(fn func(v interface{}) ([]byte, error)) *Client
- func (c *Client) SetXmlUnmarshal(fn func(data []byte, v interface{}) error) *Client
- type DumpOptions
- type Logger
- type RedirectPolicy
- func AllowedDomainRedirectPolicy(hosts ...string) RedirectPolicy
- func AllowedHostRedirectPolicy(hosts ...string) RedirectPolicy
- func MaxRedirectPolicy(noOfRedirect int) RedirectPolicy
- func NoRedirectPolicy() RedirectPolicy
- func SameDomainRedirectPolicy() RedirectPolicy
- func SameHostRedirectPolicy() RedirectPolicy
- type Request
- func AddQueryParam(key, value string) *Request
- func DisableTrace() *Request
- func EnableDump() *Request
- func EnableDumpTo(output io.Writer) *Request
- func EnableDumpToFile(filename string) *Request
- func EnableDumpWithoutBody() *Request
- func EnableDumpWithoutHeader() *Request
- func EnableDumpWithoutRequest() *Request
- func EnableDumpWithoutRequestBody() *Request
- func EnableDumpWithoutResponse() *Request
- func EnableDumpWithoutResponseBody() *Request
- func EnableTrace() *Request
- func NewRequest() *Request
- func R() *Request
- func SetBasicAuth(username, password string) *Request
- func SetBearerAuthToken(token string) *Request
- func SetBody(body interface{}) *Request
- func SetBodyBytes(body []byte) *Request
- func SetBodyJsonBytes(body []byte) *Request
- func SetBodyJsonMarshal(v interface{}) *Request
- func SetBodyJsonString(body string) *Request
- func SetBodyString(body string) *Request
- func SetBodyXmlBytes(body []byte) *Request
- func SetBodyXmlMarshal(v interface{}) *Request
- func SetBodyXmlString(body string) *Request
- func SetContentType(contentType string) *Request
- func SetContext(ctx context.Context) *Request
- func SetCookies(cookies ...*http.Cookie) *Request
- func SetDumpOptions(opt *DumpOptions) *Request
- func SetError(error interface{}) *Request
- func SetFile(paramName, filePath string) *Request
- func SetFileReader(paramName, filePath string, reader io.Reader) *Request
- func SetFiles(files map[string]string) *Request
- func SetFormData(data map[string]string) *Request
- func SetFormDataFromValues(data urlpkg.Values) *Request
- func SetHeader(key, value string) *Request
- func SetHeaders(hdrs map[string]string) *Request
- func SetOutput(output io.Writer) *Request
- func SetOutputFile(file string) *Request
- func SetPathParam(key, value string) *Request
- func SetPathParams(params map[string]string) *Request
- func SetQueryParam(key, value string) *Request
- func SetQueryParams(params map[string]string) *Request
- func SetQueryString(query string) *Request
- func SetResult(result interface{}) *Request
- func (r *Request) AddQueryParam(key, value string) *Request
- func (r *Request) Context() context.Context
- func (r *Request) Delete(url string) (*Response, error)
- func (r *Request) DisableTrace() *Request
- func (r *Request) EnableDump() *Request
- func (r *Request) EnableDumpTo(output io.Writer) *Request
- func (r *Request) EnableDumpToFile(filename string) *Request
- func (r *Request) EnableDumpWithoutBody() *Request
- func (r *Request) EnableDumpWithoutHeader() *Request
- func (r *Request) EnableDumpWithoutRequest() *Request
- func (r *Request) EnableDumpWithoutRequestBody() *Request
- func (r *Request) EnableDumpWithoutResponse() *Request
- func (r *Request) EnableDumpWithoutResponseBody() *Request
- func (r *Request) EnableTrace() *Request
- func (r *Request) Get(url string) (*Response, error)
- func (r *Request) Head(url string) (*Response, error)
- func (r *Request) MustDelete(url string) *Response
- func (r *Request) MustGet(url string) *Response
- func (r *Request) MustHead(url string) *Response
- func (r *Request) MustOptions(url string) *Response
- func (r *Request) MustPatch(url string) *Response
- func (r *Request) MustPost(url string) *Response
- func (r *Request) MustPut(url string) *Response
- func (r *Request) Options(url string) (*Response, error)
- func (r *Request) Patch(url string) (*Response, error)
- func (r *Request) Post(url string) (*Response, error)
- func (r *Request) Put(url string) (*Response, error)
- func (r *Request) Send(method, url string) (*Response, error)
- func (r *Request) SetBasicAuth(username, password string) *Request
- func (r *Request) SetBearerAuthToken(token string) *Request
- func (r *Request) SetBody(body interface{}) *Request
- func (r *Request) SetBodyBytes(body []byte) *Request
- func (r *Request) SetBodyJsonBytes(body []byte) *Request
- func (r *Request) SetBodyJsonMarshal(v interface{}) *Request
- func (r *Request) SetBodyJsonString(body string) *Request
- func (r *Request) SetBodyString(body string) *Request
- func (r *Request) SetBodyXmlBytes(body []byte) *Request
- func (r *Request) SetBodyXmlMarshal(v interface{}) *Request
- func (r *Request) SetBodyXmlString(body string) *Request
- func (r *Request) SetContentType(contentType string) *Request
- func (r *Request) SetContext(ctx context.Context) *Request
- func (r *Request) SetCookies(cookies ...*http.Cookie) *Request
- func (r *Request) SetDumpOptions(opt *DumpOptions) *Request
- func (r *Request) SetError(error interface{}) *Request
- func (r *Request) SetFile(paramName, filePath string) *Request
- func (r *Request) SetFileReader(paramName, filePath string, reader io.Reader) *Request
- func (r *Request) SetFiles(files map[string]string) *Request
- func (r *Request) SetFormData(data map[string]string) *Request
- func (r *Request) SetFormDataFromValues(data urlpkg.Values) *Request
- func (r *Request) SetHeader(key, value string) *Request
- func (r *Request) SetHeaders(hdrs map[string]string) *Request
- func (r *Request) SetOutput(output io.Writer) *Request
- func (r *Request) SetOutputFile(file string) *Request
- func (r *Request) SetPathParam(key, value string) *Request
- func (r *Request) SetPathParams(params map[string]string) *Request
- func (r *Request) SetQueryParam(key, value string) *Request
- func (r *Request) SetQueryParams(params map[string]string) *Request
- func (r *Request) SetQueryString(query string) *Request
- func (r *Request) SetResult(result interface{}) *Request
- func (r *Request) TraceInfo() TraceInfo
- type RequestMiddleware
- type Response
- func Delete(url string) (*Response, error)
- func Get(url string) (*Response, error)
- func Head(url string) (*Response, error)
- func MustDelete(url string) *Response
- func MustGet(url string) *Response
- func MustHead(url string) *Response
- func MustOptions(url string) *Response
- func MustPatch(url string) *Response
- func MustPost(url string) *Response
- func MustPut(url string) *Response
- func Options(url string) (*Response, error)
- func Patch(url string) (*Response, error)
- func Post(url string) (*Response, error)
- func Put(url string) (*Response, error)
- func (r *Response) Bytes() []byte
- func (r *Response) Dump() string
- func (r *Response) Error() interface{}
- func (r *Response) GetContentType() string
- func (r *Response) IsError() bool
- func (r *Response) IsSuccess() bool
- func (r *Response) ReceivedAt() time.Time
- func (r *Response) Result() interface{}
- func (r *Response) String() string
- func (r *Response) ToBytes() ([]byte, error)
- func (r *Response) ToString() (string, error)
- func (r *Response) TotalTime() time.Duration
- func (r *Response) TraceInfo() TraceInfo
- func (r *Response) Unmarshal(v interface{}) error
- func (r *Response) UnmarshalJson(v interface{}) error
- func (r *Response) UnmarshalXml(v interface{}) error
- type ResponseMiddleware
- type ResponseOptions
- type TLSConn
- type TraceInfo
- type Transport
- func (t *Transport) CancelRequest(req *http.Request)deprecated
- func (t *Transport) Clone() *Transport
- func (t *Transport) CloseIdleConnections()
- func (t *Transport) DisableDump()
- func (t *Transport) EnableDump(opt *DumpOptions)
- func (t *Transport) RegisterProtocol(scheme string, rt http.RoundTripper)
- func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error)
Constants ¶
This section is empty.
Variables ¶
var NoBody = noBody{}
NoBody is an io.ReadCloser with no bytes. Read always returns EOF and Close always returns nil. It can be used in an outgoing client request to explicitly signal that a request has zero bytes. An alternative, however, is to simply set Request.Body to nil.
Functions ¶
func CanonicalMIMEHeaderKey ¶
CanonicalMIMEHeaderKey returns the canonical format of the MIME header key s. The canonicalization converts the first letter and any letter following a hyphen to upper case; the rest are converted to lowercase. For example, the canonical key for "accept-encoding" is "Accept-Encoding". MIME header keys are assumed to be ASCII only. If s contains a space or invalid header field bytes, it is returned without modifications.
func SetDefaultClient ¶
func SetDefaultClient(c *Client)
SetDefaultClient override the global default Client.
Types ¶
type Client ¶
type Client struct { BaseURL string PathParams map[string]string QueryParams urlpkg.Values Headers http.Header Cookies []*http.Cookie FormData urlpkg.Values DebugLog bool AllowGetMethodPayload bool // contains filtered or unexported fields }
Client is the req's http client.
func AddCommonQueryParam ¶
AddCommonQueryParam is a global wrapper methods which delegated to the default client's AddCommonQueryParam.
func DevMode ¶
func DevMode() *Client
DevMode is a global wrapper methods which delegated to the default client's DevMode.
func DisableAllowGetMethodPayload ¶
func DisableAllowGetMethodPayload() *Client
DisableAllowGetMethodPayload is a global wrapper methods which delegated to the default client's DisableAllowGetMethodPayload.
func DisableAutoDecode ¶
func DisableAutoDecode() *Client
DisableAutoDecode is a global wrapper methods which delegated to the default client's DisableAutoDecode.
func DisableAutoReadResponse ¶
func DisableAutoReadResponse() *Client
DisableAutoReadResponse is a global wrapper methods which delegated to the default client's DisableAutoReadResponse.
func DisableCompression ¶
func DisableCompression() *Client
DisableCompression is a global wrapper methods which delegated to the default client's DisableCompression.
func DisableDebugLog ¶
func DisableDebugLog() *Client
DisableDebugLog is a global wrapper methods which delegated to the default client's DisableDebugLog.
func DisableDumpAll ¶
func DisableDumpAll() *Client
DisableDumpAll is a global wrapper methods which delegated to the default client's DisableDumpAll.
func DisableForceHTTP1 ¶ added in v3.2.0
func DisableForceHTTP1() *Client
DisableForceHTTP1 is a global wrapper methods which delegated to the default client's DisableForceHTTP1.
func DisableKeepAlives ¶
func DisableKeepAlives() *Client
DisableKeepAlives is a global wrapper methods which delegated to the default client's DisableKeepAlives.
func DisableTraceAll ¶
func DisableTraceAll() *Client
DisableTraceAll is a global wrapper methods which delegated to the default client's DisableTraceAll.
func EnableAllowGetMethodPayload ¶
func EnableAllowGetMethodPayload() *Client
EnableAllowGetMethodPayload is a global wrapper methods which delegated to the default client's EnableAllowGetMethodPayload.
func EnableAutoDecode ¶
func EnableAutoDecode() *Client
EnableAutoDecode is a global wrapper methods which delegated to the default client's EnableAutoDecode.
func EnableAutoReadResponse ¶
func EnableAutoReadResponse() *Client
EnableAutoReadResponse is a global wrapper methods which delegated to the default client's EnableAutoReadResponse.
func EnableCompression ¶
func EnableCompression() *Client
EnableCompression is a global wrapper methods which delegated to the default client's EnableCompression.
func EnableDebugLog ¶
func EnableDebugLog() *Client
EnableDebugLog is a global wrapper methods which delegated to the default client's EnableDebugLog.
func EnableDumpAll ¶
func EnableDumpAll() *Client
EnableDumpAll is a global wrapper methods which delegated to the default client's EnableDumpAll.
func EnableDumpAllAsync ¶
func EnableDumpAllAsync() *Client
EnableDumpAllAsync is a global wrapper methods which delegated to the default client's EnableDumpAllAsync.
func EnableDumpAllTo ¶
EnableDumpAllTo is a global wrapper methods which delegated to the default client's EnableDumpAllTo.
func EnableDumpAllToFile ¶
EnableDumpAllToFile is a global wrapper methods which delegated to the default client's EnableDumpAllToFile.
func EnableDumpAllWithoutBody ¶
func EnableDumpAllWithoutBody() *Client
EnableDumpAllWithoutBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutBody.
func EnableDumpAllWithoutHeader ¶
func EnableDumpAllWithoutHeader() *Client
EnableDumpAllWithoutHeader is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutHeader.
func EnableDumpAllWithoutRequest ¶ added in v3.1.0
func EnableDumpAllWithoutRequest() *Client
EnableDumpAllWithoutRequest is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutRequest.
func EnableDumpAllWithoutRequestBody ¶
func EnableDumpAllWithoutRequestBody() *Client
EnableDumpAllWithoutRequestBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutRequestBody.
func EnableDumpAllWithoutResponse ¶
func EnableDumpAllWithoutResponse() *Client
EnableDumpAllWithoutResponse is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutResponse.
func EnableDumpAllWithoutResponseBody ¶
func EnableDumpAllWithoutResponseBody() *Client
EnableDumpAllWithoutResponseBody is a global wrapper methods which delegated to the default client's EnableDumpAllWithoutResponseBody.
func EnableForceHTTP1 ¶ added in v3.2.0
func EnableForceHTTP1() *Client
EnableForceHTTP1 is a global wrapper methods which delegated to the default client's EnableForceHTTP1.
func EnableKeepAlives ¶
func EnableKeepAlives() *Client
EnableKeepAlives is a global wrapper methods which delegated to the default client's EnableKeepAlives.
func EnableTraceAll ¶
func EnableTraceAll() *Client
EnableTraceAll is a global wrapper methods which delegated to the default client's EnableTraceAll.
func OnAfterResponse ¶
func OnAfterResponse(m ResponseMiddleware) *Client
OnAfterResponse is a global wrapper methods which delegated to the default client's OnAfterResponse.
func OnBeforeRequest ¶
func OnBeforeRequest(m RequestMiddleware) *Client
OnBeforeRequest is a global wrapper methods which delegated to the default client's OnBeforeRequest.
func SetAutoDecodeAllType ¶
func SetAutoDecodeAllType() *Client
SetAutoDecodeAllType is a global wrapper methods which delegated to the default client's SetAutoDecodeAllType.
func SetAutoDecodeAllTypeFunc ¶
SetAutoDecodeAllTypeFunc is a global wrapper methods which delegated to the default client's SetAutoDecodeAllTypeFunc.
func SetAutoDecodeContentType ¶
SetAutoDecodeContentType is a global wrapper methods which delegated to the default client's SetAutoDecodeContentType.
func SetBaseURL ¶
SetBaseURL is a global wrapper methods which delegated to the default client's SetBaseURL.
func SetCertFromFile ¶
SetCertFromFile is a global wrapper methods which delegated to the default client's SetCertFromFile.
func SetCerts ¶
func SetCerts(certs ...tls.Certificate) *Client
SetCerts is a global wrapper methods which delegated to the default client's SetCerts.
func SetCommonBasicAuth ¶
SetCommonBasicAuth is a global wrapper methods which delegated to the default client's SetCommonBasicAuth.
func SetCommonBearerAuthToken ¶
SetCommonBearerAuthToken is a global wrapper methods which delegated to the default client's SetCommonBearerAuthToken.
func SetCommonContentType ¶
SetCommonContentType is a global wrapper methods which delegated to the default client's SetCommonContentType.
func SetCommonCookies ¶
SetCommonCookies is a global wrapper methods which delegated to the default client's SetCommonCookies.
func SetCommonDumpOptions ¶
func SetCommonDumpOptions(opt *DumpOptions) *Client
SetCommonDumpOptions is a global wrapper methods which delegated to the default client's SetCommonDumpOptions.
func SetCommonFormData ¶
SetCommonFormData is a global wrapper methods which delegated to the default client's SetCommonFormData.
func SetCommonFormDataFromValues ¶
SetCommonFormDataFromValues is a global wrapper methods which delegated to the default client's SetCommonFormDataFromValues.
func SetCommonHeader ¶
SetCommonHeader is a global wrapper methods which delegated to the default client's SetCommonHeader.
func SetCommonHeaders ¶
SetCommonHeaders is a global wrapper methods which delegated to the default client's SetCommonHeaders.
func SetCommonQueryParam ¶
SetCommonQueryParam is a global wrapper methods which delegated to the default client's SetCommonQueryParam.
func SetCommonQueryParams ¶
SetCommonQueryParams is a global wrapper methods which delegated to the default client's SetCommonQueryParams.
func SetCommonQueryString ¶
SetCommonQueryString is a global wrapper methods which delegated to the default client's SetCommonQueryString.
func SetCookieJar ¶
SetCookieJar is a global wrapper methods which delegated to the default client's SetCookieJar.
func SetDial ¶ added in v3.2.0
SetDial is a global wrapper methods which delegated to the default client's SetDial.
func SetDialTLS ¶ added in v3.2.0
SetDialTLS is a global wrapper methods which delegated to the default client's SetDialTLS.
func SetJsonMarshal ¶
SetJsonMarshal is a global wrapper methods which delegated to the default client's SetJsonMarshal.
func SetJsonUnmarshal ¶
SetJsonUnmarshal is a global wrapper methods which delegated to the default client's SetJsonUnmarshal.
func SetLogger ¶
SetLogger is a global wrapper methods which delegated to the default client's SetLogger.
func SetOutputDirectory ¶
SetOutputDirectory is a global wrapper methods which delegated to the default client's SetOutputDirectory.
func SetProxy ¶
SetProxy is a global wrapper methods which delegated to the default client's SetProxy.
func SetProxyURL ¶
SetProxyURL is a global wrapper methods which delegated to the default client's SetProxyURL.
func SetRedirectPolicy ¶
func SetRedirectPolicy(policies ...RedirectPolicy) *Client
SetRedirectPolicy is a global wrapper methods which delegated to the default client's SetRedirectPolicy.
func SetRootCertFromString ¶
SetRootCertFromString is a global wrapper methods which delegated to the default client's SetRootCertFromString.
func SetRootCertsFromFile ¶
SetRootCertsFromFile is a global wrapper methods which delegated to the default client's SetRootCertsFromFile.
func SetScheme ¶
SetScheme is a global wrapper methods which delegated to the default client's SetScheme.
func SetTLSClientConfig ¶
SetTLSClientConfig is a global wrapper methods which delegated to the default client's SetTLSClientConfig.
func SetTLSHandshakeTimeout ¶ added in v3.2.0
SetTLSHandshakeTimeout is a global wrapper methods which delegated to the default client's SetTLSHandshakeTimeout.
func SetTimeout ¶
SetTimeout is a global wrapper methods which delegated to the default client's SetTimeout.
func SetUserAgent ¶
SetUserAgent is a global wrapper methods which delegated to the default client's SetUserAgent.
func SetXmlMarshal ¶
SetXmlMarshal is a global wrapper methods which delegated to the default client's SetXmlMarshal.
func SetXmlUnmarshal ¶
SetXmlUnmarshal is a global wrapper methods which delegated to the default client's SetXmlUnmarshal.
func (*Client) AddCommonQueryParam ¶
AddCommonQueryParam add a URL query parameter with a key-value pair at client level
func (*Client) DevMode ¶
DevMode enables: 1. Dump content of all requests and responses to see details. 2. Output debug log for deeper insights. 3. Trace all requests, so you can get trace info to analyze performance. 4. Set User-Agent to pretend to be a web browser, avoid returning abnormal data from some sites.
func (*Client) DisableAllowGetMethodPayload ¶
DisableAllowGetMethodPayload disables sending GET method requests with body.
func (*Client) DisableAutoDecode ¶
DisableAutoDecode disable auto detect charset and decode to utf-8 (enabled by default)
func (*Client) DisableAutoReadResponse ¶
DisableAutoReadResponse disable read response body automatically (enabled by default).
func (*Client) DisableCompression ¶
DisableCompression disables the compression (enabled by default), which prevents the Transport from requesting compression with an "Accept-Encoding: gzip" request header when the Request contains no existing Accept-Encoding value. If the Transport requests gzip on its own and gets a gzipped response, it's transparently decoded in the Response.Body. However, if the user explicitly requested gzip it is not automatically uncompressed.
func (*Client) DisableDebugLog ¶
DisableDebugLog disables debug level log (disabled by default).
func (*Client) DisableDumpAll ¶
DisableDumpAll disables the dump.
func (*Client) DisableForceHTTP1 ¶ added in v3.2.0
DisableForceHTTP1 disable force using HTTP1 (disabled by default)
func (*Client) DisableKeepAlives ¶
DisableKeepAlives disables HTTP keep-alives (enabled by default) and will only use the connection to the server for a single HTTP request .
This is unrelated to the similarly named TCP keep-alives.
func (*Client) DisableTraceAll ¶
DisableTraceAll disables the trace at client level.
func (*Client) EnableAllowGetMethodPayload ¶
EnableAllowGetMethodPayload allows sending GET method requests with body.
func (*Client) EnableAutoDecode ¶
EnableAutoDecode enables auto detect charset and decode to utf-8 (enabled by default)
func (*Client) EnableAutoReadResponse ¶
EnableAutoReadResponse enable read response body automatically (enabled by default).
func (*Client) EnableCompression ¶
EnableCompression enables the compression (enabled by default), which prevents the Transport from requesting compression with an "Accept-Encoding: gzip" request header when the Request contains no existing Accept-Encoding value. If the Transport requests gzip on its own and gets a gzipped response, it's transparently decoded in the Response.Body. However, if the user explicitly requested gzip it is not automatically uncompressed.
func (*Client) EnableDebugLog ¶
EnableDebugLog enables debug level log (disabled by default).
func (*Client) EnableDumpAll ¶
EnableDumpAll enables dump for all requests, including all content for the request and response by default.
func (*Client) EnableDumpAllAsync ¶
EnableDumpAllAsync enables dump for all requests and output asynchronously, can be used for debugging in production environment without affecting performance.
func (*Client) EnableDumpAllTo ¶
EnableDumpAllTo enables dump for all requests and save to the specified io.Writer.
func (*Client) EnableDumpAllToFile ¶
EnableDumpAllToFile enables dump for all requests and save to the specified filename.
func (*Client) EnableDumpAllWithoutBody ¶
EnableDumpAllWithoutBody enables dump for all requests with only header of request and response included.
func (*Client) EnableDumpAllWithoutHeader ¶
EnableDumpAllWithoutHeader enables dump for all requests with only body of request and response included.
func (*Client) EnableDumpAllWithoutRequest ¶ added in v3.1.0
EnableDumpAllWithoutRequest enables dump for all requests with only request header and body included.
func (*Client) EnableDumpAllWithoutRequestBody ¶
EnableDumpAllWithoutRequestBody enables dump for all requests, with request body excluded, can be used in upload request to avoid dump the unreadable binary content.
func (*Client) EnableDumpAllWithoutResponse ¶
EnableDumpAllWithoutResponse enables dump for all requests with only request header and body included.
func (*Client) EnableDumpAllWithoutResponseBody ¶
EnableDumpAllWithoutResponseBody enables dump for all requests, with response body excluded, can be used in download request to avoid dump the unreadable binary content.
func (*Client) EnableForceHTTP1 ¶ added in v3.2.0
EnableForceHTTP1 enables force using HTTP1 (disabled by default)
func (*Client) EnableKeepAlives ¶
EnableKeepAlives enables HTTP keep-alives (enabled by default) and will only use the connection to the server for a single HTTP request .
This is unrelated to the similarly named TCP keep-alives.
func (*Client) EnableTraceAll ¶
EnableTraceAll enables the trace at client level.
func (*Client) OnAfterResponse ¶
func (c *Client) OnAfterResponse(m ResponseMiddleware) *Client
OnAfterResponse add a response middleware which hooks after response received.
func (*Client) OnBeforeRequest ¶
func (c *Client) OnBeforeRequest(m RequestMiddleware) *Client
OnBeforeRequest add a request middleware which hooks before request sent.
func (*Client) SetAutoDecodeAllType ¶
SetAutoDecodeAllType enables to try auto-detect and decode all content type to utf-8.
func (*Client) SetAutoDecodeAllTypeFunc ¶
SetAutoDecodeAllTypeFunc set the custmize function that determins the content-type whether if should be auto-detected and decode to utf-8
func (*Client) SetAutoDecodeContentType ¶
SetAutoDecodeContentType set the content types that will be auto-detected and decode to utf-8
func (*Client) SetBaseURL ¶
SetBaseURL set the default base url, will be used if request url is a relative url.
func (*Client) SetCertFromFile ¶
SetCertFromFile helps to set client certificates from cert and key file
func (*Client) SetCerts ¶
func (c *Client) SetCerts(certs ...tls.Certificate) *Client
SetCerts helps to set client certificates
func (*Client) SetCommonBasicAuth ¶
SetCommonBasicAuth set the basic auth for all requests.
func (*Client) SetCommonBearerAuthToken ¶
SetCommonBearerAuthToken set the bearer auth token for all requests.
func (*Client) SetCommonContentType ¶
SetCommonContentType set the `Content-Type` header for all requests.
func (*Client) SetCommonCookies ¶
SetCommonCookies set cookies at client level.
func (*Client) SetCommonDumpOptions ¶
func (c *Client) SetCommonDumpOptions(opt *DumpOptions) *Client
SetCommonDumpOptions configures the underlying Transport's DumpOptions
func (*Client) SetCommonFormData ¶
SetCommonFormData set the form data from map for all requests which method allows payload.
func (*Client) SetCommonFormDataFromValues ¶
SetCommonFormDataFromValues set the form data from url.Values for all requests which method allows payload.
func (*Client) SetCommonHeader ¶
SetCommonHeader set a header for all requests.
func (*Client) SetCommonHeaders ¶
SetCommonHeaders set headers for all requests.
func (*Client) SetCommonQueryParam ¶
SetCommonQueryParam set a URL query parameter with a key-value pair at client level.
func (*Client) SetCommonQueryParams ¶
SetCommonQueryParams sets the URL query parameters with a map at client level.
func (*Client) SetCommonQueryString ¶
SetCommonQueryString set URL query parameters using the raw query string.
func (*Client) SetCookieJar ¶
SetCookieJar set the `CookeJar` to the underlying `http.Client`
func (*Client) SetDial ¶ added in v3.2.0
func (c *Client) SetDial(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
SetDial set the customized Dial function.
func (*Client) SetDialTLS ¶ added in v3.2.0
func (c *Client) SetDialTLS(fn func(ctx context.Context, network, addr string) (net.Conn, error)) *Client
SetDialTLS set the customized DialTLSContext
func (*Client) SetJsonMarshal ¶
SetJsonMarshal set json marshal function which will be used to marshal request body.
func (*Client) SetJsonUnmarshal ¶
SetJsonUnmarshal set the JSON unmarshal function which will be used to unmarshal response body.
func (*Client) SetOutputDirectory ¶
SetOutputDirectory set output directory that response will be downloaded to.
func (*Client) SetProxyURL ¶
SetProxyURL set a proxy from the proxy url.
func (*Client) SetRedirectPolicy ¶
func (c *Client) SetRedirectPolicy(policies ...RedirectPolicy) *Client
SetRedirectPolicy helps to set the RedirectPolicy.
func (*Client) SetRootCertFromString ¶
SetRootCertFromString helps to set root CA cert from string
func (*Client) SetRootCertsFromFile ¶
SetRootCertsFromFile helps to set root certs from files
func (*Client) SetScheme ¶
SetScheme sets custom default scheme in the client, will be used when there is no scheme in the request url.
func (*Client) SetTLSClientConfig ¶
SetTLSClientConfig sets the client tls config.
func (*Client) SetTLSHandshakeTimeout ¶ added in v3.2.0
SetTLSHandshakeTimeout set the TLS handshake timeout.
func (*Client) SetTimeout ¶
SetTimeout set the timeout for all requests.
func (*Client) SetUserAgent ¶
SetUserAgent set the "User-Agent" header for all requests.
func (*Client) SetXmlMarshal ¶
SetXmlMarshal set the XML marshal function which will be used to marshal request body.
type DumpOptions ¶
type DumpOptions struct { Output io.Writer RequestHeader bool RequestBody bool ResponseHeader bool ResponseBody bool Async bool }
DumpOptions controls the dump behavior.
func (*DumpOptions) Clone ¶
func (do *DumpOptions) Clone() *DumpOptions
type Logger ¶
type Logger interface { Errorf(format string, v ...interface{}) Warnf(format string, v ...interface{}) Debugf(format string, v ...interface{}) }
Logger interface is to abstract the logging from Resty. Gives control to the Resty users, choice of the logger.
type RedirectPolicy ¶
func AllowedDomainRedirectPolicy ¶
func AllowedDomainRedirectPolicy(hosts ...string) RedirectPolicy
AllowedDomainRedirectPolicy allows redirect only if the redirected domain match one of the domain that specified.
func AllowedHostRedirectPolicy ¶
func AllowedHostRedirectPolicy(hosts ...string) RedirectPolicy
AllowedHostRedirectPolicy allows redirect only if the redirected host match one of the host that specified.
func MaxRedirectPolicy ¶
func MaxRedirectPolicy(noOfRedirect int) RedirectPolicy
MaxRedirectPolicy specifies the max number of redirect
func NoRedirectPolicy ¶
func NoRedirectPolicy() RedirectPolicy
NoRedirectPolicy disable redirect behaviour
func SameDomainRedirectPolicy ¶
func SameDomainRedirectPolicy() RedirectPolicy
func SameHostRedirectPolicy ¶
func SameHostRedirectPolicy() RedirectPolicy
SameHostRedirectPolicy allows redirect only if the redirected host is the same as original host, e.g. redirect to "www.imroc.cc" from "imroc.cc" is not the allowed.
type Request ¶
type Request struct { URL string PathParams map[string]string QueryParams urlpkg.Values FormData urlpkg.Values Headers http.Header Cookies []*http.Cookie Result interface{} Error interface{} RawRequest *http.Request StartTime time.Time // contains filtered or unexported fields }
Request is the http request
func AddQueryParam ¶
AddQueryParam is a global wrapper methods which delegated to the default client, create a request and AddQueryParam for request.
func DisableTrace ¶
func DisableTrace() *Request
DisableTrace is a global wrapper methods which delegated to the default client, create a request and DisableTrace for request.
func EnableDump ¶
func EnableDump() *Request
EnableDump is a global wrapper methods which delegated to the default client, create a request and EnableDump for request.
func EnableDumpTo ¶
EnableDumpTo is a global wrapper methods which delegated to the default client, create a request and EnableDumpTo for request.
func EnableDumpToFile ¶
EnableDumpToFile is a global wrapper methods which delegated to the default client, create a request and EnableDumpToFile for request.
func EnableDumpWithoutBody ¶
func EnableDumpWithoutBody() *Request
EnableDumpWithoutBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutBody for request.
func EnableDumpWithoutHeader ¶
func EnableDumpWithoutHeader() *Request
EnableDumpWithoutHeader is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutHeader for request.
func EnableDumpWithoutRequest ¶
func EnableDumpWithoutRequest() *Request
EnableDumpWithoutRequest is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutRequest for request.
func EnableDumpWithoutRequestBody ¶ added in v3.1.0
func EnableDumpWithoutRequestBody() *Request
EnableDumpWithoutRequestBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutRequestBody for request.
func EnableDumpWithoutResponse ¶
func EnableDumpWithoutResponse() *Request
EnableDumpWithoutResponse is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutResponse for request.
func EnableDumpWithoutResponseBody ¶ added in v3.1.0
func EnableDumpWithoutResponseBody() *Request
EnableDumpWithoutResponseBody is a global wrapper methods which delegated to the default client, create a request and EnableDumpWithoutResponseBody for request.
func EnableTrace ¶
func EnableTrace() *Request
EnableTrace is a global wrapper methods which delegated to the default client, create a request and EnableTrace for request.
func NewRequest ¶
func NewRequest() *Request
NewRequest is a global wrapper methods which delegated to the default client's NewRequest.
func R ¶
func R() *Request
R is a global wrapper methods which delegated to the default client's R().
func SetBasicAuth ¶
SetBasicAuth is a global wrapper methods which delegated to the default client, create a request and SetBasicAuth for request.
func SetBearerAuthToken ¶
SetBearerAuthToken is a global wrapper methods which delegated to the default client, create a request and SetBearerAuthToken for request.
func SetBody ¶
func SetBody(body interface{}) *Request
SetBody is a global wrapper methods which delegated to the default client, create a request and SetBody for request.
func SetBodyBytes ¶
SetBodyBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyBytes for request.
func SetBodyJsonBytes ¶
SetBodyJsonBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonBytes for request.
func SetBodyJsonMarshal ¶
func SetBodyJsonMarshal(v interface{}) *Request
SetBodyJsonMarshal is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonMarshal for request.
func SetBodyJsonString ¶
SetBodyJsonString is a global wrapper methods which delegated to the default client, create a request and SetBodyJsonString for request.
func SetBodyString ¶
SetBodyString is a global wrapper methods which delegated to the default client, create a request and SetBodyString for request.
func SetBodyXmlBytes ¶
SetBodyXmlBytes is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlBytes for request.
func SetBodyXmlMarshal ¶
func SetBodyXmlMarshal(v interface{}) *Request
SetBodyXmlMarshal is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlMarshal for request.
func SetBodyXmlString ¶
SetBodyXmlString is a global wrapper methods which delegated to the default client, create a request and SetBodyXmlString for request.
func SetContentType ¶
SetContentType is a global wrapper methods which delegated to the default client, create a request and SetContentType for request.
func SetContext ¶
SetContext is a global wrapper methods which delegated to the default client, create a request and SetContext for request.
func SetCookies ¶
SetCookies is a global wrapper methods which delegated to the default client, create a request and SetCookies for request.
func SetDumpOptions ¶
func SetDumpOptions(opt *DumpOptions) *Request
func SetError ¶
func SetError(error interface{}) *Request
SetError is a global wrapper methods which delegated to the default client, create a request and SetError for request.
func SetFile ¶
SetFile is a global wrapper methods which delegated to the default client, create a request and SetFile for request.
func SetFileReader ¶
SetFileReader is a global wrapper methods which delegated to the default client, create a request and SetFileReader for request.
func SetFiles ¶
SetFiles is a global wrapper methods which delegated to the default client, create a request and SetFiles for request.
func SetFormData ¶
SetFormData is a global wrapper methods which delegated to the default client, create a request and SetFormData for request.
func SetFormDataFromValues ¶
SetFormDataFromValues is a global wrapper methods which delegated to the default client, create a request and SetFormDataFromValues for request.
func SetHeader ¶
SetHeader is a global wrapper methods which delegated to the default client, create a request and SetHeader for request.
func SetHeaders ¶
SetHeaders is a global wrapper methods which delegated to the default client, create a request and SetHeaders for request.
func SetOutput ¶
SetOutput is a global wrapper methods which delegated to the default client, create a request and SetOutput for request.
func SetOutputFile ¶
SetOutputFile is a global wrapper methods which delegated to the default client, create a request and SetOutputFile for request.
func SetPathParam ¶
SetPathParam is a global wrapper methods which delegated to the default client, create a request and SetPathParam for request.
func SetPathParams ¶
SetPathParams is a global wrapper methods which delegated to the default client, create a request and SetPathParams for request.
func SetQueryParam ¶
SetQueryParam is a global wrapper methods which delegated to the default client, create a request and SetQueryParam for request.
func SetQueryParams ¶
SetQueryParams is a global wrapper methods which delegated to the default client, create a request and SetQueryParams for request.
func SetQueryString ¶
SetQueryString is a global wrapper methods which delegated to the default client, create a request and SetQueryString for request.
func SetResult ¶
func SetResult(result interface{}) *Request
SetResult is a global wrapper methods which delegated to the default client, create a request and SetResult for request.
func (*Request) AddQueryParam ¶
AddQueryParam add a URL query parameter with a key-value pair at request level.
func (*Request) Context ¶
Context method returns the Context if its already set in request otherwise it creates new one using `context.Background()`.
func (*Request) DisableTrace ¶
DisableTrace disables trace.
func (*Request) EnableDump ¶
EnableDump enables dump, including all content for the request and response by default.
func (*Request) EnableDumpTo ¶
EnableDumpTo enables dump and save to the specified io.Writer.
func (*Request) EnableDumpToFile ¶
EnableDumpToFile enables dump and save to the specified filename.
func (*Request) EnableDumpWithoutBody ¶
EnableDumpWithoutBody enables dump only header for the request and response.
func (*Request) EnableDumpWithoutHeader ¶
EnableDumpWithoutHeader enables dump only body for the request and response.
func (*Request) EnableDumpWithoutRequest ¶
EnableDumpWithoutRequest enables dump only response.
func (*Request) EnableDumpWithoutRequestBody ¶ added in v3.1.0
EnableDumpWithoutRequestBody enables dump with request body excluded, can be used in upload request to avoid dump the unreadable binary content.
func (*Request) EnableDumpWithoutResponse ¶
EnableDumpWithoutResponse enables dump only request.
func (*Request) EnableDumpWithoutResponseBody ¶ added in v3.1.0
EnableDumpWithoutResponseBody enables dump with response body excluded, can be used in download request to avoid dump the unreadable binary content.
func (*Request) MustDelete ¶
MustDelete like Delete, panic if error happens, should only be used to test without error handling.
func (*Request) MustGet ¶
MustGet like Get, panic if error happens, should only be used to test without error handling.
func (*Request) MustHead ¶
MustHead like Head, panic if error happens, should only be used to test without error handling.
func (*Request) MustOptions ¶
MustOptions like Options, panic if error happens, should only be used to test without error handling.
func (*Request) MustPatch ¶
MustPatch like Patch, panic if error happens, should only be used to test without error handling.
func (*Request) MustPut ¶
MustPut like Put, panic if error happens, should only be used to test without error handling.
func (*Request) SetBasicAuth ¶
SetBasicAuth set the basic auth at request level.
func (*Request) SetBearerAuthToken ¶
SetBearerAuthToken set the bearer auth token at request level.
func (*Request) SetBody ¶
SetBody set the request body, accepts string, []byte, io.Reader, map and struct.
func (*Request) SetBodyBytes ¶
SetBodyBytes set the request body as []byte.
func (*Request) SetBodyJsonBytes ¶
SetBodyJsonBytes set the request body as []byte and set Content-Type header as "application/json; charset=utf-8"
func (*Request) SetBodyJsonMarshal ¶
SetBodyJsonMarshal set the request body that marshaled from object, and set Content-Type header as "application/json; charset=utf-8"
func (*Request) SetBodyJsonString ¶
SetBodyJsonString set the request body as string and set Content-Type header as "application/json; charset=utf-8"
func (*Request) SetBodyString ¶
SetBodyString set the request body as string.
func (*Request) SetBodyXmlBytes ¶
SetBodyXmlBytes set the request body as []byte and set Content-Type header as "text/xml; charset=utf-8"
func (*Request) SetBodyXmlMarshal ¶
SetBodyXmlMarshal set the request body that marshaled from object, and set Content-Type header as "text/xml; charset=utf-8"
func (*Request) SetBodyXmlString ¶
SetBodyXmlString set the request body as string and set Content-Type header as "text/xml; charset=utf-8"
func (*Request) SetContentType ¶
SetContentType set the `Content-Type` for the request.
func (*Request) SetContext ¶
SetContext method sets the context.Context for current Request. It allows to interrupt the request execution if ctx.Done() channel is closed. See https://blog.golang.org/context article and the "context" package documentation.
func (*Request) SetCookies ¶
SetCookies set cookies at request level.
func (*Request) SetDumpOptions ¶
func (r *Request) SetDumpOptions(opt *DumpOptions) *Request
SetDumpOptions sets DumpOptions at request level.
func (*Request) SetError ¶
SetError set the result that response body will be unmarshaled to if request is error ( status `code >= 400`).
func (*Request) SetFile ¶
SetFile sets up a multipart form, read file from filePath automatically to upload.
func (*Request) SetFileReader ¶
SetFileReader sets up a multipart form with a reader to upload file.
func (*Request) SetFiles ¶
SetFiles sets up a multipart form from a map, which key is the param name, value is the file path.
func (*Request) SetFormData ¶
SetFormData set the form data from map, not used if method not allow payload.
func (*Request) SetFormDataFromValues ¶
SetFormDataFromValues set the form data from url.Values, not used if method not allow payload.
func (*Request) SetHeaders ¶
SetHeaders set the header at request level.
func (*Request) SetOutputFile ¶
SetOutputFile the file that response body will be downloaded to.
func (*Request) SetPathParam ¶
SetPathParam sets the URL path parameters from a key-value paire at request level.
func (*Request) SetPathParams ¶
SetPathParams sets the URL path parameters from a map at request level.
func (*Request) SetQueryParam ¶
SetQueryParam set an URL query parameter with a key-value pair at request level.
func (*Request) SetQueryParams ¶
SetQueryParams sets the URL query parameters with a map at client level.
func (*Request) SetQueryString ¶
SetQueryString set URL query parameters using the raw query string.
type RequestMiddleware ¶
RequestMiddleware type is for request middleware, called before a request is sent
type Response ¶
Response is the http response.
func Delete ¶
Delete is a global wrapper methods which delegated to the default client, create a request and Delete for request.
func Get ¶
Get is a global wrapper methods which delegated to the default client, create a request and Get for request.
func Head ¶
Head is a global wrapper methods which delegated to the default client, create a request and Head for request.
func MustDelete ¶
MustDelete is a global wrapper methods which delegated to the default client, create a request and MustDelete for request.
func MustGet ¶
MustGet is a global wrapper methods which delegated to the default client, create a request and MustGet for request.
func MustHead ¶
MustHead is a global wrapper methods which delegated to the default client, create a request and MustHead for request.
func MustOptions ¶
MustOptions is a global wrapper methods which delegated to the default client, create a request and MustOptions for request.
func MustPatch ¶
MustPatch is a global wrapper methods which delegated to the default client, create a request and MustPatch for request.
func MustPost ¶
MustPost is a global wrapper methods which delegated to the default client, create a request and Get for request.
func MustPut ¶
MustPut is a global wrapper methods which delegated to the default client, create a request and MustPut for request.
func Options ¶
Options is a global wrapper methods which delegated to the default client, create a request and Options for request.
func Patch ¶
Patch is a global wrapper methods which delegated to the default client, create a request and Patch for request.
func Post ¶
Post is a global wrapper methods which delegated to the default client, create a request and Post for request.
func Put ¶
Put is a global wrapper methods which delegated to the default client, create a request and Put for request.
func (*Response) Bytes ¶
Bytes return the response body as []bytes that hava already been read, could be nil if not read, the following cases are already read:
- `Request.SetResult` or `Request.SetError` is called.
- `Client.DisableAutoReadResponse(false)` is not called, also `Request.SetOutput` and `Request.SetOutputFile` is not called.
func (*Response) Dump ¶
Dump return the string content that have been dumped for the request. `Request.Dump` or `Request.DumpXXX` MUST have been called.
func (*Response) Error ¶
func (r *Response) Error() interface{}
Error returns the error object if it has one.
func (*Response) GetContentType ¶
GetContentType return the `Content-Type` header value.
func (*Response) IsError ¶
IsError method returns true if HTTP status `code >= 400` otherwise false.
func (*Response) IsSuccess ¶
IsSuccess method returns true if HTTP status `code >= 200 and <= 299` otherwise false.
func (*Response) ReceivedAt ¶
ReceivedAt returns the timestamp that response we received.
func (*Response) Result ¶
func (r *Response) Result() interface{}
Result returns the response value as an object if it has one
func (*Response) String ¶
String returns the response body as string that hava already been read, could be nil if not read, the following cases are already read:
- `Request.SetResult` or `Request.SetError` is called.
- `Client.DisableAutoReadResponse(false)` is not called, also `Request.SetOutput` and `Request.SetOutputFile` is not called.
func (*Response) ToBytes ¶
ToBytes returns the response body as []byte, read body if not have been read.
func (*Response) ToString ¶
ToString returns the response body as string, read body if not have been read.
func (*Response) TotalTime ¶
TotalTime returns the total time of the request, from request we sent to response we received.
func (*Response) Unmarshal ¶
Unmarshal unmarshals response body into the specified object according to response `Content-Type`.
func (*Response) UnmarshalJson ¶
UnmarshalJson unmarshals JSON response body into the specified object.
func (*Response) UnmarshalXml ¶
UnmarshalXml unmarshals XML response body into the specified object.
type ResponseMiddleware ¶
ResponseMiddleware type is for response middleware, called after a response has been received
type ResponseOptions ¶
type ResponseOptions struct { // DisableAutoDecode, if true, prevents auto detect response // body's charset and decode it to utf-8 DisableAutoDecode bool // AutoDecodeContentType specifies an optional function for determine // whether the response body should been auto decode to utf-8. // Only valid when DisableAutoDecode is true. AutoDecodeContentType func(contentType string) bool }
ResponseOptions determines that how should the response been processed.
type TLSConn ¶ added in v3.2.0
type TLSConn interface { net.Conn ConnectionState() tls.ConnectionState Handshake() error }
TLSConn is the recommended interface for the connection returned by the DailTLS function (Client.SetDialTLS, Transport.DialTLSContext), so that the TLS handshake negotiation can automatically decide whether to use HTTP2 or HTTP1 (ALPN). If this interface is not implemented, HTTP1 will be used by default.
type TraceInfo ¶
type TraceInfo struct { // DNSLookupTime is a duration that transport took to perform // DNS lookup. DNSLookupTime time.Duration // ConnectTime is a duration that took to obtain a successful connection. ConnectTime time.Duration // TCPConnectTime is a duration that took to obtain the TCP connection. TCPConnectTime time.Duration // TLSHandshakeTime is a duration that TLS handshake took place. TLSHandshakeTime time.Duration // FirstResponseTime is a duration that server took to respond first byte since // connection ready (after tls handshake if it's tls and not a reused connection). FirstResponseTime 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 // RemoteAddr returns the remote network address. RemoteAddr net.Addr }
type Transport ¶
type Transport struct { // ForceHTTP1 force using HTTP/1.1 ForceHTTP1 bool // Proxy specifies a function to return a proxy for a given // Request. If the function returns a non-nil error, the // request is aborted with the provided error. // // The proxy type is determined by the URL scheme. "http", // "https", and "socks5" are supported. If the scheme is empty, // "http" is assumed. // // If Proxy is nil or returns a nil *URL, no proxy is used. Proxy func(*http.Request) (*url.URL, error) // DialContext specifies the dial function for creating unencrypted TCP connections. // If DialContext is nil, then the transport dials using package net. // // DialContext runs concurrently with calls to RoundTrip. // A RoundTrip call that initiates a dial may end up using // a connection dialed previously when the earlier connection // becomes idle before the later DialContext completes. DialContext func(ctx context.Context, network, addr string) (net.Conn, error) // DialTLSContext specifies an optional dial function for creating // TLS connections for non-proxied HTTPS requests. // // If DialTLSContext is nil, DialContext and TLSClientConfig are used. // // If DialTLSContext is set, the Dial and DialContext hooks are not used for HTTPS // requests and the TLSClientConfig and TLSHandshakeTimeout // are ignored. The returned net.Conn is assumed to already be // past the TLS handshake. DialTLSContext func(ctx context.Context, network, addr string) (net.Conn, error) // TLSClientConfig specifies the TLS configuration to use with // tls.Client. // If nil, the default configuration is used. // If non-nil, HTTP/2 support may not be enabled by default. TLSClientConfig *tls.Config // TLSHandshakeTimeout specifies the maximum amount of time waiting to // wait for a TLS handshake. Zero means no timeout. TLSHandshakeTimeout time.Duration // DisableKeepAlives, if true, disables HTTP keep-alives and // will only use the connection to the server for a single // HTTP request. // // This is unrelated to the similarly named TCP keep-alives. DisableKeepAlives bool // DisableCompression, if true, prevents the Transport from // requesting compression with an "Accept-Encoding: gzip" // request header when the Request contains no existing // Accept-Encoding value. If the Transport requests gzip on // its own and gets a gzipped response, it's transparently // decoded in the Response.Body. However, if the user // explicitly requested gzip it is not automatically // uncompressed. DisableCompression bool // MaxIdleConns controls the maximum number of idle (keep-alive) // connections across all hosts. Zero means no limit. MaxIdleConns int // MaxIdleConnsPerHost, if non-zero, controls the maximum idle // (keep-alive) connections to keep per-host. If zero, // defaultMaxIdleConnsPerHost is used. MaxIdleConnsPerHost int // MaxConnsPerHost optionally limits the total number of // connections per host, including connections in the dialing, // active, and idle states. On limit violation, dials will block. // // Zero means no limit. MaxConnsPerHost int // IdleConnTimeout is the maximum amount of time an idle // (keep-alive) connection will remain idle before closing // itself. // Zero means no limit. IdleConnTimeout time.Duration // ResponseHeaderTimeout, if non-zero, specifies the amount of // time to wait for a server's response headers after fully // writing the request (including its body, if any). This // time does not include the time to read the response body. ResponseHeaderTimeout time.Duration // ExpectContinueTimeout, if non-zero, specifies the amount of // time to wait for a server's first response headers after fully // writing the request headers if the request has an // "Expect: 100-continue" header. Zero means no timeout and // causes the body to be sent immediately, without // waiting for the server to approve. // This time does not include the time to send the request header. ExpectContinueTimeout time.Duration // TLSNextProto specifies how the Transport switches to an // alternate protocol (such as HTTP/2) after a TLS ALPN // protocol negotiation. If Transport dials an TLS connection // with a non-empty protocol name and TLSNextProto contains a // map entry for that key (such as "h2"), then the func is // called with the request's authority (such as "example.com" // or "example.com:1234") and the TLS connection. The function // must return a http.RoundTripper that then handles the request. // If TLSNextProto is not nil, HTTP/2 support is not enabled // automatically. TLSNextProto map[string]func(authority string, c TLSConn) http.RoundTripper // ProxyConnectHeader optionally specifies headers to send to // proxies during CONNECT requests. // To set the header dynamically, see GetProxyConnectHeader. ProxyConnectHeader http.Header // GetProxyConnectHeader optionally specifies a func to return // headers to send to proxyURL during a CONNECT request to the // ip:port target. // If it returns an error, the Transport's RoundTrip fails with // that error. It can return (nil, nil) to not add headers. // If GetProxyConnectHeader is non-nil, ProxyConnectHeader is // ignored. GetProxyConnectHeader func(ctx context.Context, proxyURL *url.URL, target string) (http.Header, error) // MaxResponseHeaderBytes specifies a limit on how many // response bytes are allowed in the server's response // header. // // Zero means to use a default limit. MaxResponseHeaderBytes int64 // WriteBufferSize specifies the size of the write buffer used // when writing to the transport. // If zero, a default (currently 4KB) is used. WriteBufferSize int // ReadBufferSize specifies the size of the read buffer used // when reading from the transport. // If zero, a default (currently 4KB) is used. ReadBufferSize int // ForceAttemptHTTP2 controls whether HTTP/2 is enabled when a non-zero // Dial, DialTLS, or DialContext func or TLSClientConfig is provided. // By default, use of any those fields conservatively disables HTTP/2. // To use a custom dialer or TLS config and still attempt HTTP/2 // upgrades, set this to true. ForceAttemptHTTP2 bool *ResponseOptions Debugf func(format string, v ...interface{}) // contains filtered or unexported fields }
Transport is an implementation of http.RoundTripper that supports HTTP, HTTPS, and HTTP proxies (for either HTTP or HTTPS with CONNECT).
By default, Transport caches connections for future re-use. This may leave many open connections when accessing many hosts. This behavior can be managed using Transport's CloseIdleConnections method and the MaxIdleConnsPerHost and DisableKeepAlives fields.
Transports should be reused instead of created as needed. Transports are safe for concurrent use by multiple goroutines.
A Transport is a low-level primitive for making HTTP and HTTPS requests. For high-level functionality, such as cookies and redirects, see Client.
Transport uses HTTP/1.1 for HTTP URLs and either HTTP/1.1 or HTTP/2 for HTTPS URLs, depending on whether the server supports HTTP/2, and how the Transport is configured. The DefaultTransport supports HTTP/2. To explicitly enable HTTP/2 on a transport, use golang.org/x/net/http2 and call ConfigureTransport. See the package docs for more about HTTP/2.
Responses with status codes in the 1xx range are either handled automatically (100 expect-continue) or ignored. The one exception is HTTP status code 101 (Switching Protocols), which is considered a terminal status and returned by RoundTrip. To see the ignored 1xx responses, use the httptrace trace package's ClientTrace.Got1xxResponse.
Transport only retries a request upon encountering a network error if the request is idempotent and either has no body or has its Request.GetBody defined. HTTP requests are considered idempotent if they have HTTP methods GET, HEAD, OPTIONS, or TRACE; or if their Header map contains an "Idempotency-Key" or "X-Idempotency-Key" entry. If the idempotency key value is a zero-length slice, the request is treated as idempotent but the header is not sent on the wire.
func (*Transport) CancelRequest
deprecated
CancelRequest cancels an in-flight request by closing its connection. CancelRequest should only be called after RoundTrip has returned.
Deprecated: Use Request.WithContext to create a request with a cancelable context instead. CancelRequest cannot cancel HTTP/2 requests.
func (*Transport) CloseIdleConnections ¶
func (t *Transport) CloseIdleConnections()
CloseIdleConnections closes any connections which were previously connected from previous requests but are now sitting idle in a "keep-alive" state. It does not interrupt any connections currently in use.
func (*Transport) EnableDump ¶
func (t *Transport) EnableDump(opt *DumpOptions)
EnableDump enables the dump for all requests with specified dump options.
func (*Transport) RegisterProtocol ¶
func (t *Transport) RegisterProtocol(scheme string, rt http.RoundTripper)
RegisterProtocol registers a new protocol with scheme. The Transport will pass requests using the given scheme to rt. It is rt's responsibility to simulate HTTP request semantics.
RegisterProtocol can be used by other packages to provide implementations of protocol schemes like "ftp" or "file".
If rt.RoundTrip returns ErrSkipAltProtocol, the Transport will handle the RoundTrip itself for that one request, as if the protocol were not registered.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
Package internal contains HTTP internals shared by net/http and net/http/httputil.
|
Package internal contains HTTP internals shared by net/http and net/http/httputil. |
godebug
Package godebug parses the GODEBUG environment variable.
|
Package godebug parses the GODEBUG environment variable. |
testcert
Package testcert contains a test-only localhost certificate.
|
Package testcert contains a test-only localhost certificate. |