Documentation
¶
Index ¶
- Constants
- Variables
- func Do(ctx context.Context, client *http.Client, req *http.Request) (statusCode int, header http.Header, body []byte, duration time.Duration, ...)
- func NewCredentialRequest(ctx context.Context, target string, value string, loc CredentialLocation) (*http.Request, error)
- func NewRequest(ctx context.Context, method, target string, body io.Reader, ...) (*http.Request, error)
- type CredentialLocation
- type Option
- type Probe
- type RequestBuilder
- type RequestMutator
- func WithAPIKeyHeader(name, value string) RequestMutator
- func WithAPIKeyQuery(name, value string) RequestMutator
- func WithAuthCookie(name, value string) RequestMutator
- func WithBasicAuth(username, password string) RequestMutator
- func WithBearerToken(token string) RequestMutator
- func WithCookie(cookie *http.Cookie) RequestMutator
- func WithFormCredential(name, value string) RequestMutator
- func WithHeader(name, value string) RequestMutator
- func WithQuery(name, value string) RequestMutator
Constants ¶
const ( CredentialLocationHeader = "header" CredentialLocationCookie = "cookie" CredentialLocationQuery = "query" CredentialLocationBody = "body" )
Variables ¶
var ErrMaxRetriesExceeded = errors.New("probe: max retries exceeded")
ErrMaxRetriesExceeded is returned when all retry attempts have been exhausted.
Functions ¶
func Do ¶ added in v0.3.0
func Do(ctx context.Context, client *http.Client, req *http.Request) (statusCode int, header http.Header, body []byte, duration time.Duration, err error)
Do sends req via client and returns the response's status code, headers, fully-drained body, and duration. The response body is fully read and closed before Do returns.
func NewCredentialRequest ¶ added in v0.3.0
func NewCredentialRequest(ctx context.Context, target string, value string, loc CredentialLocation) (*http.Request, error)
NewCredentialRequest builds a request against target with value placed at loc. Header, cookie, and query placements produce a GET; body placement switches to POST via WithFormCredential.
func NewRequest ¶ added in v0.3.0
func NewRequest(ctx context.Context, method, target string, body io.Reader, mutators ...RequestMutator) (*http.Request, error)
NewRequest builds an *http.Request via http.NewRequestWithContext and applies mutators to it in order. It is the single entry point checks should use instead of calling http.NewRequestWithContext directly.
Types ¶
type CredentialLocation ¶ added in v0.3.0
type CredentialLocation struct {
In string // CredentialLocationHeader (default), *Cookie, *Query, or *Body
Name string // header/cookie/query/form-field name
Prefix string // value prefix, e.g. "Bearer "
}
CredentialLocation describes where to place a credential value in an HTTP request: a header (default), a cookie, a query parameter, or a form-encoded body field. It's the declarative counterpart to the With* mutators above, for callers (e.g. a security check) that pick the placement at runtime instead of hardcoding one mutator.
func (CredentialLocation) Validate ¶ added in v0.3.0
func (l CredentialLocation) Validate() error
Validate rejects an unknown In value.
func (CredentialLocation) WithDefaults ¶ added in v0.3.0
func (l CredentialLocation) WithDefaults() CredentialLocation
WithDefaults fills unset fields, defaulting to an Authorization: Bearer header when nothing is overridden.
type Option ¶
type Option func(*config)
Option configures a Probe.
func WithMaxRetries ¶
WithMaxRetries sets the maximum number of retry attempts (0 = no retries, one attempt only).
func WithRetryDelay ¶
WithRetryDelay sets the base delay between retries. The actual delay grows exponentially with full jitter, capped at 60 seconds.
func WithTimeout ¶
WithTimeout sets the timeout on the *http.Client returned by Client(). It has no effect on the underlying transport.
func WithTransport ¶
func WithTransport(t http.RoundTripper) Option
WithTransport sets the underlying http.RoundTripper used for actual requests. Defaults to http.DefaultTransport.
func WithUserAgent ¶
WithUserAgent sets the User-Agent header sent on every request.
type Probe ¶
type Probe struct {
// contains filtered or unexported fields
}
Probe implements http.RoundTripper with retry, rate-limit compliance, and User-Agent injection. Use Client() to get a standard *http.Client backed by this probe, giving access to the full net/http API with no verb restrictions.
func (*Probe) Client ¶
Client returns a *http.Client backed by this probe. All requests made through the returned client benefit from retry, rate-limit compliance, and User-Agent injection — for any HTTP method.
type RequestBuilder ¶ added in v0.3.0
RequestBuilder builds a request for a single probe attempt.
type RequestMutator ¶ added in v0.3.0
RequestMutator mutates a *http.Request built by NewRequest, in place. Mutators are applied in the order given; the first error returned short-circuits the chain and is returned from NewRequest.
func WithAPIKeyHeader ¶ added in v0.3.0
func WithAPIKeyHeader(name, value string) RequestMutator
WithAPIKeyHeader sets an arbitrary named header to value, e.g. a custom API-key header such as X-API-Key.
func WithAPIKeyQuery ¶ added in v0.3.0
func WithAPIKeyQuery(name, value string) RequestMutator
WithAPIKeyQuery sets an arbitrary named query parameter to value.
func WithAuthCookie ¶ added in v0.3.0
func WithAuthCookie(name, value string) RequestMutator
WithAuthCookie attaches a session/auth cookie with secure defaults (Secure, HttpOnly, SameSite=Strict).
func WithBasicAuth ¶ added in v0.3.0
func WithBasicAuth(username, password string) RequestMutator
WithBasicAuth sets HTTP Basic authentication credentials on the request.
func WithBearerToken ¶ added in v0.3.0
func WithBearerToken(token string) RequestMutator
WithBearerToken sets the Authorization header to "Bearer <token>".
func WithCookie ¶ added in v0.3.0
func WithCookie(cookie *http.Cookie) RequestMutator
WithCookie attaches a cookie to the request.
func WithFormCredential ¶ added in v0.3.0
func WithFormCredential(name, value string) RequestMutator
WithFormCredential places name=value as a urlencoded form body field, switching the request method to POST.
func WithHeader ¶ added in v0.3.0
func WithHeader(name, value string) RequestMutator
WithHeader sets (overwrites) a single header value.
func WithQuery ¶ added in v0.3.0
func WithQuery(name, value string) RequestMutator
WithQuery sets (overwrites) a single URL query parameter.