http

package
v1.14.0 Latest Latest
Warning

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

Go to latest
Published: Nov 26, 2023 License: Apache-2.0 Imports: 14 Imported by: 17

Documentation

Index

Constants

View Source
const (
	// DefaultRedirects is the default number of times an Attacker follows
	// redirects.
	DefaultRedirects = 10
	// DefaultTimeout is the default amount of time an Attacker waits for a request
	// before it times out.
	DefaultTimeout = 30 * time.Second
	// DefaultConnections is the default amount of max open idle connections per
	// target host.
	DefaultConnections = 10000
	// DefaultMaxConnections is the default amount of connections per target
	// host.
	DefaultMaxConnections = 0
	// DefaultWorkers is the default initial number of workers used to carry an attack.
	DefaultWorkers = 10
	// DefaultMaxWorkers is the default maximum number of workers used to carry an attack.
	DefaultMaxWorkers = math.MaxUint64
	// DefaultMaxBody is the default max number of bytes to be read from response bodies.
	// Defaults to no limit.
	DefaultMaxBody = int64(-1)
	// NoFollow is the value when redirects are not followed but marked successful
	NoFollow = -1
)
View Source
const (
	GET     = http.MethodGet
	POST    = http.MethodPost
	HEAD    = http.MethodHead
	PUT     = http.MethodPut
	PATCH   = http.MethodPatch // RFC 5789
	DELETE  = http.MethodDelete
	CONNECT = http.MethodConnect
	OPTIONS = http.MethodOptions
	TRACE   = http.MethodTrace

	ContentEncoding = "Content-Encoding"
	LastModified    = "Last-Modified"
	IfModifiedSince = "If-Modified-Since"
)

Variables

View Source
var DefaultRoundTripper http.RoundTripper = &http.Transport{
	Proxy: http.ProxyFromEnvironment,
	DialContext: (&net.Dialer{
		Timeout:   30 * time.Second,
		KeepAlive: 30 * time.Second,
	}).DialContext,
	IdleConnTimeout:       30 * time.Second,
	TLSHandshakeTimeout:   10 * time.Second,
	ResponseHeaderTimeout: 10 * time.Second,
	ExpectContinueTimeout: 1 * time.Second,
	MaxIdleConns:          100,
	MaxIdleConnsPerHost:   DefaultConnections,
	MaxConnsPerHost:       DefaultMaxConnections,
}

DefaultRoundTripper is used if no RoundTripper is set in Config.

Functions

func HttpGet

func HttpGet(url string) ([]byte, error)

func HttpRequest

func HttpRequest(url string, method string) ([]byte, error)

func Request

func Request(url string, method string, header ...map[string]any) (data []byte, lastModified time.Time, err error)

Request http request, 支持传入header

Types

type Response

type Response struct {
	StatusCode    int
	ContentLength int
	LastModified  time.Time
	Body          []byte
}

Jump to

Keyboard shortcuts

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