phttp

package
Version: v0.1.3 Latest Latest
Warning

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

Go to latest
Published: Nov 3, 2017 License: MPL-2.0 Imports: 17 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 NewDialer

func NewDialer(conf DialerConfig) netutil.Dialer

func NewHTTP2Transport

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

func NewTransport

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

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() int
}

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 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 {
	Log        *zap.Logger // If nil, zap.L() will be used.
	DebugLog   bool        // Automaticaly set in Bind if Log accepts debug messages.
	Config     BaseGunConfig
	Do         func(r *http.Request) (*http.Response, error) // Required.
	Connect    func(ctx context.Context) error               // Optional hook.
	OnClose    func() error                                  // Optional. Called on Close().
	Aggregator netsample.Aggregator                          // Lazy set via BindResultTo.
}

func (*BaseGun) Bind

func (b *BaseGun) Bind(aggregator netsample.Aggregator)

TODO(skipor): pass logger here in https://github.com/yandex/pandora/issues/57

func (*BaseGun) Close

func (b *BaseGun) Close() error

func (*BaseGun) Shoot

func (b *BaseGun) Shoot(ctx context.Context, ammo Ammo)

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

type BaseGunConfig

type BaseGunConfig struct {
	AutoTag AutoTagConfig `config:"auto-tag"`
}

func NewDefaultBaseGunConfig

func NewDefaultBaseGunConfig() BaseGunConfig

type Client

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

type ClientConfig

type ClientConfig struct {
	Redirect  bool            // When true, follow HTTP redirects.
	Dialer    DialerConfig    `config:"dial"`
	Transport TransportConfig `config:",squash"`
}

func NewDefaultClientConfig

func NewDefaultClientConfig() ClientConfig

type ClientGunConfig

type ClientGunConfig struct {
	Target string `validate:"endpoint,required"`
	SSL    bool
	Base   BaseGunConfig `config:",squash"`
}

func NewDefaultClientGunConfig

func NewDefaultClientGunConfig() ClientGunConfig

type ConnectGun

type ConnectGun struct {
	BaseGun
	// contains filtered or unexported fields
}

func NewConnectGun

func NewConnectGun(conf ConnectGunConfig) *ConnectGun

func (*ConnectGun) Do

func (g *ConnectGun) Do(req *http.Request) (*http.Response, error)

type ConnectGunConfig

type ConnectGunConfig struct {
	Target        string       `validate:"endpoint,required"`
	ConnectSSL    bool         `config:"connect-ssl"` // Defines if tunnel encrypted.
	SSL           bool         // As in HTTP gun, defines scheme for http requests.
	Client        ClientConfig `config:",squash"`
	BaseGunConfig `config:",squash"`
}

func NewDefaultConnectGunConfig

func NewDefaultConnectGunConfig() ConnectGunConfig

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 NewDefaultDialerConfig

func NewDefaultDialerConfig() DialerConfig

type Gun

type Gun interface {
	Shoot(context.Context, Ammo)
	Bind(netsample.Aggregator)
}

type HTTP2GunConfig

type HTTP2GunConfig struct {
	Gun    ClientGunConfig `config:",squash"`
	Client ClientConfig    `config:",squash"`
}

func NewDefaultHTTP2GunConfig

func NewDefaultHTTP2GunConfig() HTTP2GunConfig

type HTTPGun

type HTTPGun struct {
	BaseGun
	// contains filtered or unexported fields
}

func NewClientGun

func NewClientGun(client Client, conf ClientGunConfig) *HTTPGun

func NewHTTP2Gun

func NewHTTP2Gun(conf HTTP2GunConfig) (*HTTPGun, error)

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

func NewHTTPGun

func NewHTTPGun(conf HTTPGunConfig) *HTTPGun

func (*HTTPGun) Do

func (g *HTTPGun) Do(req *http.Request) (*http.Response, error)

type HTTPGunConfig

type HTTPGunConfig struct {
	Gun    ClientGunConfig `config:",squash"`
	Client ClientConfig    `config:",squash"`
}

func NewDefaultHTTPGunConfig

func NewDefaultHTTPGunConfig() HTTPGunConfig

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 NewDefaultTransportConfig

func NewDefaultTransportConfig() TransportConfig

Directories

Path Synopsis
ammo
Code generated by mockery v1.0.0
Code generated by mockery v1.0.0

Jump to

Keyboard shortcuts

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