Documentation
¶
Overview ¶
Package httpx is Stampede's HTTP/1.1 and HTTP/2 driver. It builds clients that behave like real users (per-user connection pools, cookie jars, TLS session reuse) and measures every request phase with httptrace.
Index ¶
- Constants
- func ClassifyError(err error) string
- func Dialer(o Options) func(ctx context.Context, network, addr string) (net.Conn, error)
- func NewClient(t http.RoundTripper, o Options) *http.Client
- func NewTransport(o Options) *http.Transport
- func ResetCookies(c *http.Client)
- func StatusError(code int) string
- func Trace(ctx context.Context, r *Result) context.Context
- type DNSCache
- type Options
- type Result
Constants ¶
const ErrorSnippet = 512
Do sends req and reads the response. Up to maxBody bytes are kept in Result.Body; the rest is read and counted but discarded so connections can be reused and download time is measured fully. keepBody=false discards the body, except the first ErrorSnippet bytes of an error response (status 400 and above), kept for error examples. ErrorSnippet is how much of an error response's body Do keeps when the caller did not ask for the body.
Variables ¶
This section is empty.
Functions ¶
func ClassifyError ¶
ClassifyError maps a transport error to a short, bounded label used in reports.
func Dialer ¶
Dialer is the dial function the options describe: the test or emulation dialer if set, else a TCP dialer that uses the DNS cache. Other drivers (gRPC) dial through it so they resolve names the same way.
func NewClient ¶
func NewClient(t http.RoundTripper, o Options) *http.Client
NewClient wraps a transport with a fresh cookie jar and redirect policy.
func NewTransport ¶
NewTransport builds a transport. One per virtual user gives browser-like connection behaviour; one shared transport behaves like a service client.
func ResetCookies ¶
ResetCookies gives the client an empty cookie jar, as for a new session.
Types ¶
type DNSCache ¶
type DNSCache struct {
TTL time.Duration
Resolver *net.Resolver
// contains filtered or unexported fields
}
DNSCache resolves host names once per TTL and shares the answer between virtual users, the way an operating system's resolver cache does for real clients. Without it every new connection waits on a lookup, which skews connect timing and can stall a load generator during ramp-up.
func NewDNSCache ¶
NewDNSCache caches answers for ttl (default 30s).
type Options ¶
type Options struct {
HTTP2 bool
// H2C speaks HTTP/2 without TLS to http:// URLs, with prior knowledge
// (no upgrade from HTTP/1.1), as gRPC and many internal services do.
H2C bool
DisableKeepAlive bool
InsecureSkipVerify bool
// MaxRedirects: 0 means the default of 10, negative disables following.
MaxRedirects int
// MaxConnsPerHost bounds a shared pool (0 = unlimited).
MaxConnsPerHost int
// Dialer allows tests and network emulation to replace dialing.
DialContext func(ctx context.Context, network, addr string) (net.Conn, error)
// DNS caches lookups across connections; nil resolves on every dial.
DNS *DNSCache
// TLSResumption is where TLS sessions are kept for resumption: "shared"
// (one cache for the process, the default), "per-transport" (a cache
// per transport: per virtual user when each has its own) or "off"
// (every connection makes a full handshake).
TLSResumption string
}
Options configures a client.
type Result ¶
type Result struct {
Start time.Time
End time.Time
Phases [metrics.NumPhases]time.Duration
Status int
Header http.Header
Cookies []*http.Cookie
Body []byte
BytesIn int64
BytesOut int64
Proto string
Reused bool
Err error
// contains filtered or unexported fields
}
Result is a completed exchange.