rq: github.com/ddo/rq/client Index | Files | Directories

package client

import "github.com/ddo/rq/client"


Package Files

client.go helper.go redirect.go send.go transport.go


var DefaultCheckRedirect = RedirectAfterN(defaultRedirects)

DefaultCheckRedirect returns http.Client.CheckRedirect func with defaultRedirects

var DefaultClient = New(nil)

DefaultClient has default timeout and stdlib default transport no cookie management

var NoCheckRedirect = RedirectAfterN(0)

NoCheckRedirect returns http.Client.CheckRedirect func with no redirect

func ApplyDefaultRq Uses

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

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

func RedirectAfterN Uses

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

RedirectAfterN returns http.Client.CheckRedirect func

func Send Uses

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

type Client Uses

type Client struct {
    // contains filtered or unexported fields

Client contains stdlib http client and other custom client settings

func New Uses

func New(opt *Option) *Client

New returns new client which init with provided options

func (*Client) Send Uses

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 Uses

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 Uses

func (c *Client) UnSetProxy()

UnSetProxy unsets client proxy

type Option Uses

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



Package client imports 10 packages (graph) and is imported by 3 packages. Updated 2019-08-31. Refresh now. Tools for package owners.