req

package module
v0.0.0-...-ecadf10 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 25 Imported by: 1

README

Deprecated!!!

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultConfig = &Config{
		InsecureSkipVerify: true,
		AutoReferrer:       true,
		Timeout:            30 * time.Second,
		KeepAlive:          30 * time.Second,
		Header:             fake.Headers(),
	}

	ErrMaxRedirects = errors.New(`req: stopped after 10 redirects`)
)

Functions

func CustomResolver

func CustomResolver(r *resolver.Resolver) func(ctx context.Context, network, addr string) ([]net.IPAddr, string, error)

func GetHeaderByMap

func GetHeaderByMap(h map[string]string) http.Header

func RetryLengthTrigger

func RetryLengthTrigger(resp *http.Response) bool

func RetryStatusTrigger

func RetryStatusTrigger(resp *http.Response) bool

func SleepRand

func SleepRand(min, max, step time.Duration) func(*http.Request) time.Duration

Types

type Client

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

func New

func New(config *Config) *Client

func (*Client) Client

func (c *Client) Client() *http.Client

func (*Client) Delete

func (c *Client) Delete(url string) Response

func (*Client) Do

func (c *Client) Do(request *http.Request) (resp Response)

func (*Client) Get

func (c *Client) Get(url string) Response

func (*Client) Head

func (c *Client) Head(url string) Response

func (*Client) NewRequest

func (c *Client) NewRequest(method, link string, body io.Reader) *http.Request

func (*Client) Patch

func (c *Client) Patch(url string, body io.Reader) Response

func (*Client) Post

func (c *Client) Post(url string, body io.Reader) Response

func (*Client) PostForm

func (c *Client) PostForm(url string, data url.Values) Response

func (*Client) PostJson

func (c *Client) PostJson(url string, j interface{}) (resp Response)

func (*Client) Put

func (c *Client) Put(url string, body io.Reader) Response

type Config

type Config struct {
	BeforeFunc   func(req *http.Request)
	AfterFunc    func(req *http.Request, resp Response)
	SleepFunc    func(req *http.Request) time.Duration
	ResolveFunc  func(ctx context.Context, network, addr string) (ips []net.IPAddr, port string, err error)
	ProxyFunc    func(req *http.Request) (*url.URL, error)
	RedirectFunc func(req *http.Request, via []*http.Request) error

	MaxRetryAttempts int
	RetryDelay       time.Duration
	RetryTrigger     func(resp *http.Response) bool

	Header http.Header

	FakeIP             bool
	InsecureSkipVerify bool
	AutoReferrer       bool
	UseCookie          bool
	DisableKeepAlive   bool
	DisableCompression bool

	MaxConnsPerHost        int
	MaxIdleConns           int
	MaxIdleConnsPerHost    int
	MaxResponseHeaderBytes int64
	MaxRedirects           int

	Timeout   time.Duration
	KeepAlive time.Duration

	WriteBufferSize int
	ReadBufferSize  int

	CachePath string
}

type Response

type Response struct {
	Redirects []*url.URL
	// contains filtered or unexported fields
}

func (Response) Body

func (r Response) Body() io.ReadCloser

func (Response) ContentLength

func (r Response) ContentLength() int64

func (Response) Error

func (r Response) Error() error

func (Response) Header

func (r Response) Header() http.Header

func (Response) ReadAll

func (r Response) ReadAll() []byte

func (Response) ReadJSON

func (r Response) ReadJSON(i interface{}) error

func (Response) ReadLimit

func (r Response) ReadLimit(n int64) []byte

func (Response) Request

func (r Response) Request() *http.Request

func (Response) Response

func (r Response) Response() *http.Response

func (Response) SaveBody

func (r Response) SaveBody(filename string) (int64, error)

func (Response) SaveHeader

func (r Response) SaveHeader(filename string) error

func (Response) StatusCode

func (r Response) StatusCode() int

func (Response) TLS

func (r Response) TLS() *tls.ConnectionState

Jump to

Keyboard shortcuts

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