Documentation ¶
Index ¶
- Constants
- func Reset()
- type Client
- func AcquireLock() *Client
- func BasicAuth(username, password string) *Client
- func BearerToken(token string) *Client
- func Connect(url string) *Client
- func Cookies(cookies ...*http.Cookie) *Client
- func Delete(url string) *Client
- func DisableKeepAlives() *Client
- func DisableProxy() *Client
- func DisableRedirect() *Client
- func DisableSession() *Client
- func DisableVerify() *Client
- func Files(files ...*File) *Client
- func Form(form Value) *Client
- func Get(url string) *Client
- func Head(url string) *Client
- func Headers(headers Value) *Client
- func JSON(data Data) *Client
- func New() *Client
- func Options(url string) *Client
- func Params(params Value) *Client
- func Patch(url string) *Client
- func Post(url string) *Client
- func Put(url string) *Client
- func Trace(url string) *Client
- func WithClientCertificates(certs ...tls.Certificate) *Client
- func WithContext(ctx context.Context) *Client
- func WithCookieJar(jar http.CookieJar) *Client
- func WithProxy(url string) *Client
- func WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
- func WithRootCAs(pemFilePath string) *Client
- func WithTimeout(timeout time.Duration) *Client
- func WithTransport(transport http.RoundTripper) *Client
- func (c *Client) AcquireLock() *Client
- func (c *Client) BasicAuth(username, password string) *Client
- func (c *Client) BearerToken(token string) *Client
- func (c *Client) Connect(url string) *Client
- func (c *Client) Cookies(cookies ...*http.Cookie) *Client
- func (c *Client) Delete(url string) *Client
- func (c *Client) DisableKeepAlives() *Client
- func (c *Client) DisableProxy() *Client
- func (c *Client) DisableRedirect() *Client
- func (c *Client) DisableSession() *Client
- func (c *Client) DisableVerify() *Client
- func (c *Client) Files(files ...*File) *Client
- func (c *Client) Form(form Value) *Client
- func (c *Client) Get(url string) *Client
- func (c *Client) Head(url string) *Client
- func (c *Client) Headers(headers Value) *Client
- func (c *Client) JSON(data Data) *Client
- func (c *Client) Options(url string) *Client
- func (c *Client) Params(params Value) *Client
- func (c *Client) Patch(url string) *Client
- func (c *Client) Post(url string) *Client
- func (c *Client) Put(url string) *Client
- func (c *Client) Reset()
- func (c *Client) Send() *Response
- func (c *Client) Trace(url string) *Client
- func (c *Client) WithClientCertificates(certs ...tls.Certificate) *Client
- func (c *Client) WithContext(ctx context.Context) *Client
- func (c *Client) WithCookieJar(jar http.CookieJar) *Client
- func (c *Client) WithProxy(url string) *Client
- func (c *Client) WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
- func (c *Client) WithRootCAs(pemFilePath string) *Client
- func (c *Client) WithTimeout(timeout time.Duration) *Client
- func (c *Client) WithTransport(transport http.RoundTripper) *Client
- type Data
- type File
- type Response
- type Value
Constants ¶
const ( // Version of grequests. Version = "0.1" // ContentType is the same as "Content-Type". ContentType = "Content-Type" // TypeForm is the same as "application/x-www-form-urlencoded". TypeForm = "application/x-www-form-urlencoded" // TypeJSON is the same as "application/json". TypeJSON = "application/json" // MethodGet represents GET HTTP method MethodGet = "GET" // MethodHead represents HEAD HTTP method MethodHead = "HEAD" // MethodPost represents POST HTTP method MethodPost = "POST" // MethodPut represents PUT HTTP method MethodPut = "PUT" // MethodPatch represents PATCH HTTP method MethodPatch = "PATCH" // MethodDelete represents DELETE HTTP method MethodDelete = "DELETE" // MethodConnect represents CONNECT HTTP method MethodConnect = "CONNECT" // MethodOptions represents OPTIONS HTTP method MethodOptions = "OPTIONS" // MethodTrace represents TRACE HTTP method MethodTrace = "TRACE" )
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client defines a client.
func AcquireLock ¶
func AcquireLock() *Client
AcquireLock locks the default client. Use grequests across goroutines you must call AcquireLock for each request in the beginning. Necessary, otherwise might cause data race.
func BearerToken ¶
BearerToken sets bearer token of the default client.
func DisableKeepAlives ¶
func DisableKeepAlives() *Client
DisableKeepAlives disables HTTP keep-alives of the default client. HTTP keep-alives is enabled by default.
func DisableProxy ¶
func DisableProxy() *Client
DisableProxy lets the default client not use proxy. grequests uses proxy from environment by default.
func DisableRedirect ¶
func DisableRedirect() *Client
DisableRedirect lets the default client not redirect HTTP requests. HTTP requests redirection is enabled by default.
func DisableSession ¶
func DisableSession() *Client
DisableSession lets the default client not use cookie jar. Session is enabled by default, grequests use cookie jar to manage cookie automatically.
func DisableVerify ¶
func DisableVerify() *Client
DisableVerify lets the default client not verify the server's TLS certificate. TLS certificate verification is enabled by default.
func WithClientCertificates ¶
func WithClientCertificates(certs ...tls.Certificate) *Client
WithClientCertificates appends client certificates of the default client.
func WithContext ¶
WithContext sets context of the default client.
func WithCookieJar ¶
WithCookieJar sets cookie jar of the default client.
func WithRedirectPolicy ¶
WithRedirectPolicy sets redirect policy of the default client.
func WithRootCAs ¶
WithRootCAs appends root certificate authorities of the default client.
func WithTimeout ¶
WithTimeout sets timeout of the default client.
func WithTransport ¶
func WithTransport(transport http.RoundTripper) *Client
WithTransport sets transport of the default client.
func (*Client) AcquireLock ¶
AcquireLock locks c. Use grequests across goroutines you must call AcquireLock for each request in the beginning. Necessary, otherwise might cause data race.
func (*Client) BearerToken ¶
BearerToken sets bearer token of c.
func (*Client) DisableKeepAlives ¶
DisableKeepAlives disables HTTP keep-alives of c. HTTP keep-alives is enabled by default.
func (*Client) DisableProxy ¶
DisableProxy lets c not use proxy. grequests uses proxy from environment by default.
func (*Client) DisableRedirect ¶
DisableRedirect lets c not redirect HTTP requests. HTTP requests redirection is enabled by default.
func (*Client) DisableSession ¶
DisableSession lets c not use cookie jar. Session is enabled by default, grequests use cookie jar to manage cookie automatically.
func (*Client) DisableVerify ¶
DisableVerify lets c not verify the server's TLS certificate. TLS certificate verification enabled by default.
func (*Client) Reset ¶
func (c *Client) Reset()
Reset resets state of c so that other requests can acquire lock.
func (*Client) WithClientCertificates ¶
func (c *Client) WithClientCertificates(certs ...tls.Certificate) *Client
WithClientCertificates appends client certificates of c.
func (*Client) WithContext ¶
WithContext sets context of c.
func (*Client) WithCookieJar ¶
WithCookieJar sets cookie jar of c.
func (*Client) WithRedirectPolicy ¶
func (c *Client) WithRedirectPolicy(policy func(req *http.Request, via []*http.Request) error) *Client
WithRedirectPolicy sets redirect policy of c.
func (*Client) WithRootCAs ¶
WithRootCAs appends root certificate authorities of c.
func (*Client) WithTimeout ¶
WithTimeout sets timeout of c.
func (*Client) WithTransport ¶
func (c *Client) WithTransport(transport http.RoundTripper) *Client
WithTransport sets transport of c.
type Data ¶
type Data map[string]interface{}
Data is the same as map[string]interface{}, used for JSON payload.
type Response ¶
Response wrap HTTP response and request error.
func Send ¶
func Send() *Response
Send uses the default client to send the HTTP request and returns the response.
func (*Response) EnsureStatus2xx ¶
EnsureStatus2xx ensures the HTTP response status code of r must be 2xx.
func (*Response) EnsureStatusOk ¶
EnsureStatusOk ensures the HTTP response status code of r must be 200.