client

package
v0.0.0-...-b3daa55 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 28, 2019 License: Apache-2.0 Imports: 10 Imported by: 7

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DefaultCheckRedirect = RedirectAfterN(defaultRedirects)

DefaultCheckRedirect returns http.Client.CheckRedirect func with defaultRedirects

View Source
var DefaultClient = New(nil)

DefaultClient has default timeout and stdlib default transport no cookie management

View Source
var NoCheckRedirect = RedirectAfterN(0)

NoCheckRedirect returns http.Client.CheckRedirect func with no redirect

Functions

func ApplyDefaultRq

func ApplyDefaultRq(defaultRq, _rq *rq.Rq) (newRq *rq.Rq)

ApplyDefaultRq overrides Rq properties with default value if key is not set

func RedirectAfterN

func RedirectAfterN(n int) func(req *http.Request, via []*http.Request) error

RedirectAfterN returns http.Client.CheckRedirect func

func Send

func Send(r *rq.Rq, read bool) (data []byte, res *http.Response, err error)

Send is the wrapper of #Send but use the default client

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client contains stdlib http client and other custom client settings

func New

func New(opt *Option) *Client

New returns new client which init with provided options

func (*Client) Send

func (c *Client) Send(r *rq.Rq, read bool) (data []byte, res *http.Response, err error)

Send sends the request and read it if read is true remember to close the res.Body if read is false Send also set content-type to application/x-www-form-urlencoded if form is available

func (*Client) SetProxy

func (c *Client) SetProxy(rawURL string) (err error)

SetProxy sets client proxy by url string if url is empty, no proxy is used

func (*Client) UnSetProxy

func (c *Client) UnSetProxy()

UnSetProxy unsets client proxy

type Option

type Option struct {
	Timeout time.Duration // if 0, default timeout will be applied

	Jar *jar.Jar // if Jar is nil, there no cookie jar

	Proxy     string // Proxy option is the sugar syntax for Transport.Proxy
	Transport http.RoundTripper

	CheckRedirect func(req *http.Request, via []*http.Request) error

	DefaultRq *rq.Rq
}

Option contains client settings

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL