Documentation
¶
Overview ¶
Package useragent is the User-Agent the platform presents to an upstream it calls, and the one rule for when it is sent: on every outbound request that does not already carry one.
Go's net/http sends "Go-http-client/1.1" when a request names no User-Agent, and a web application firewall in front of a public endpoint refuses that value (#1679). The product string names the platform and its version so an operator reading an upstream's access log can tell the platform's traffic from any other Go program's, and a WAF rule can be written for it.
The rule is applied at the http.RoundTripper level rather than at each request-building site so every request a connection's client sends is covered in one place: a tool call, a page of a walk, a schema introspection, and the token request an OAuth library builds out of the caller's sight. A header the operator pinned in static_headers, or one a caller supplied per call, is already on the request when it reaches the transport and is left alone.
Index ¶
Constants ¶
const Header = "User-Agent"
Header is the request header this package sets.
Variables ¶
This section is empty.
Functions ¶
func Effective ¶
Effective is the User-Agent a request carrying h is sent with: the value h already holds, or Product when it holds none. It is the one definition of the rule the transport applies, so a message that names the User-Agent a request went out with (the graphql kind's introspection refusal) reads it from here rather than restating it.
func Product ¶
func Product() string
Product is the User-Agent the platform sends when a request names none: the product name and the build's version.
func Transport ¶
func Transport(base http.RoundTripper) http.RoundTripper
Transport wraps base so every request it sends carries a User-Agent. A nil base wraps http.DefaultTransport, matching what an http.Client with a nil Transport would have used.
func Wraps ¶
func Wraps(rt http.RoundTripper) (base http.RoundTripper, ok bool)
Wraps reports whether rt is this package's transport and returns the RoundTripper it wraps, for a test that asserts on the transport beneath it (a dial timeout, a TLS config).
Types ¶
This section is empty.