http

package
v1.21.0 Latest Latest
Warning

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

Go to latest
Published: Mar 30, 2024 License: Apache-2.0 Imports: 15 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 (
	MethodGet     = http.MethodGet
	MethodPost    = http.MethodPost
	MethodHead    = http.MethodHead
	MethodPut     = http.MethodPut
	MethodPatch   = http.MethodPatch // RFC 5789
	MethodDelete  = http.MethodDelete
	MethodConnect = http.MethodConnect
	MethodOptions = http.MethodOptions
	MethodTrace   = http.MethodTrace

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

	ApplicationJson = "application/json" + ";" + charsetUtf8
	ApplicationForm = "application/x-www-form-urlencoded" + ";" + charsetUtf8
)

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 Get added in v1.14.6

func Get(url string, header ...map[string]any) ([]byte, error)

Get HTTP协议GET请求

func HttpRequest

func HttpRequest(url string, method string, header ...map[string]any) ([]byte, error)

HttpRequest HTTP 请求

func Post added in v1.14.7

func Post(url string, content string, header ...map[string]any) (data []byte, err error)

Post HTTP协议POST请求

func Request

func Request(url string, method string, content 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