phttp

package
v0.5.32 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2024 License: MPL-2.0 Imports: 22 Imported by: 0

Documentation

Overview

package phttp (pandora http) contains pandora extension points for HTTP related protocols.

Index

Constants

View Source
const (
	EmptyTag = "__EMPTY__"
)

Variables

This section is empty.

Functions

func GetBody

func GetBody(req *http.Request) []byte

func NewDialer

func NewDialer(conf DialerConfig) netutil.Dialer

func NewHTTP2Transport

func NewHTTP2Transport(conf TransportConfig, dial netutil.DialerFunc, target string) *http.Transport

func NewTransport

func NewTransport(conf TransportConfig, dial netutil.DialerFunc, target string) *http.Transport

func PreResolveTargetAddr added in v0.5.22

func PreResolveTargetAddr(clientConf *ClientConfig, target string) (string, error)

DNS resolve optimisation. When DNSCache turned off - do nothing extra, host will be resolved on every shoot. When using resolved target, don't use DNS caching logic - it is useless. If we can resolve accessible target addr - use it as target, not use caching. Otherwise just use DNS cache - we should not fail shooting, we should try to connect on every shoot. DNS cache will save resolved addr after first successful connect.

func WrapGun

func WrapGun(g Gun) core.Gun

Types

type Ammo

type Ammo interface {
	// TODO(skipor): instead of sample use it wrapper with httptrace and more usable interface.
	Request() (*http.Request, *netsample.Sample)
	// Id unique ammo id. Usually equals to ammo num got from provider.
	ID() uint64
	IsInvalid() bool
}

Ammo ammo interface for http based guns. http ammo providers should produce ammo that implements Ammo. http guns should use convert ammo to Ammo, not to specific implementation. Returned request have

type AnswLogConfig

type AnswLogConfig struct {
	Enabled bool   `config:"enabled"`
	Path    string `config:"path"`
	Filter  string `config:"filter" valid:"oneof=all warning error"`
}

type AutoTagConfig

type AutoTagConfig struct {
	Enabled     bool `config:"enabled"`
	URIElements int  `config:"uri-elements" validate:"min=1"` // URI elements used to autotagging
	NoTagOnly   bool `config:"no-tag-only"`                   // When true, autotagged only ammo that has no tag before.
}

AutoTagConfig configure automatic tags generation based on ammo URI. First AutoTag URI path elements becomes tag. Example: /my/very/deep/page?id=23&param=33 -> /my/very when uri-elements: 2.

type BaseGun

type BaseGun struct {
	DebugLog          bool // Automaticaly set in Bind if Log accepts debug messages.
	Config            GunConfig
	Connect           func(ctx context.Context) error // Optional hook.
	OnClose           func() error                    // Optional. Called on Close().
	Aggregator        netsample.Aggregator            // Lazy set via BindResultTo.
	AnswLog           *zap.Logger
	Client            Client
	ClientConstructor func() Client

	core.GunDeps
}

func NewBaseGun added in v0.5.22

func NewBaseGun(clientConstructor ClientConstructor, cfg GunConfig, answLog *zap.Logger) *BaseGun

func NewConnectGun

func NewConnectGun(cfg GunConfig, answLog *zap.Logger) *BaseGun

func NewHTTP1Gun added in v0.5.22

func NewHTTP1Gun(cfg GunConfig, answLog *zap.Logger) *BaseGun

func NewHTTP2Gun

func NewHTTP2Gun(cfg GunConfig, answLog *zap.Logger) (*BaseGun, error)

NewHTTP2Gun return simple HTTP/2 gun that can shoot sequentially through one connection.

func (*BaseGun) Bind

func (b *BaseGun) Bind(aggregator netsample.Aggregator, deps core.GunDeps) error

func (*BaseGun) Close

func (b *BaseGun) Close() error

func (*BaseGun) Shoot

func (b *BaseGun) Shoot(ammo Ammo)

Shoot is thread safe iff Do and Connect hooks are thread safe.

func (*BaseGun) WarmUp added in v0.5.22

func (b *BaseGun) WarmUp(opts *warmup.Options) (any, error)

type Client

type Client interface {
	Do(req *http.Request) (*http.Response, error)
	CloseIdleConnections() // We should close idle conns after gun close.
}

func HTTP1ClientConstructor added in v0.5.22

func HTTP1ClientConstructor(clientConfig ClientConfig, target string) Client

func HTTP2ClientConstructor added in v0.5.22

func HTTP2ClientConstructor(clientConfig ClientConfig, target string) Client

func NewRedirectingClient added in v0.5.22

func NewRedirectingClient(tr *http.Transport, redirect bool) Client

type ClientConfig

type ClientConfig struct {
	Redirect   bool            // When true, follow HTTP redirects.
	Dialer     DialerConfig    `config:"dial"`
	Transport  TransportConfig `config:",squash"`
	ConnectSSL bool            `config:"connect-ssl"` // Defines if tunnel encrypted.
}

func DefaultClientConfig

func DefaultClientConfig() ClientConfig

type ClientConstructor added in v0.5.22

type ClientConstructor func(clientConfig ClientConfig, target string) Client

type DialerConfig

type DialerConfig struct {
	DNSCache bool `config:"dns-cache" map:"-"`

	Timeout   time.Duration `config:"timeout"`
	DualStack bool          `config:"dual-stack"`

	// IPv4/IPv6 settings should not matter really,
	// because target should be dialed using pre-resolved addr.
	FallbackDelay time.Duration `config:"fallback-delay"`
	KeepAlive     time.Duration `config:"keep-alive"`
}

DialerConfig can be mapped on net.Dialer. Set net.Dialer for details.

func DefaultDialerConfig

func DefaultDialerConfig() DialerConfig

type Gun

type Gun interface {
	Shoot(ammo Ammo)
	Bind(sample netsample.Aggregator, deps core.GunDeps) error
	WarmUp(opts *warmup.Options) (any, error)
}

type GunConfig added in v0.5.24

type GunConfig struct {
	Client         ClientConfig `config:",squash"`
	Target         string       `validate:"endpoint,required"`
	TargetResolved string       `config:"-"`
	SSL            bool

	AutoTag      AutoTagConfig   `config:"auto-tag"`
	AnswLog      AnswLogConfig   `config:"answlog"`
	HTTPTrace    HTTPTraceConfig `config:"httptrace"`
	SharedClient struct {
		ClientNumber int  `config:"client-number,omitempty"`
		Enabled      bool `config:"enabled"`
	} `config:"shared-client,omitempty"`
}

func DefaultConnectGunConfig

func DefaultConnectGunConfig() GunConfig

func DefaultHTTP2GunConfig

func DefaultHTTP2GunConfig() GunConfig

func DefaultHTTPGunConfig

func DefaultHTTPGunConfig() GunConfig

type HTTPTraceConfig

type HTTPTraceConfig struct {
	DumpEnabled  bool `config:"dump"`
	TraceEnabled bool `config:"trace"`
}

type SharedDeps added in v0.5.22

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

type TraceTimings

type TraceTimings struct {
	GotConnTime          time.Time
	GetConnTime          time.Time
	DNSStartTime         time.Time
	DNSDoneTime          time.Time
	ConnectDoneTime      time.Time
	ConnectStartTime     time.Time
	WroteRequestTime     time.Time
	GotFirstResponseByte time.Time
}

func CreateHTTPTrace added in v0.5.9

func CreateHTTPTrace() (*httptrace.ClientTrace, *TraceTimings)

func (*TraceTimings) GetConnectTime

func (t *TraceTimings) GetConnectTime() time.Duration

func (*TraceTimings) GetLatency

func (t *TraceTimings) GetLatency() time.Duration

func (*TraceTimings) GetReceiveTime

func (t *TraceTimings) GetReceiveTime() time.Duration

func (*TraceTimings) GetSendTime

func (t *TraceTimings) GetSendTime() time.Duration

type TransportConfig

type TransportConfig struct {
	TLSHandshakeTimeout   time.Duration `config:"tls-handshake-timeout"`
	DisableKeepAlives     bool          `config:"disable-keep-alives"`
	DisableCompression    bool          `config:"disable-compression"`
	MaxIdleConns          int           `config:"max-idle-conns"`
	MaxIdleConnsPerHost   int           `config:"max-idle-conns-per-host"`
	IdleConnTimeout       time.Duration `config:"idle-conn-timeout"`
	ResponseHeaderTimeout time.Duration `config:"response-header-timeout"`
	ExpectContinueTimeout time.Duration `config:"expect-continue-timeout"`
}

TransportConfig can be mapped on http.Transport. See http.Transport for details.

func DefaultTransportConfig

func DefaultTransportConfig() TransportConfig

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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