Documentation
¶
Overview ¶
Package urlmap is the load balancer's URL map routing engine (FR-LB-003): a pure library that compiles a compute v1 UrlMap and selects, for a request, the backend (service or bucket), redirect, URL rewrite and header actions exactly as GCP's Application Load Balancers do:
- host rules: exact host (with port, then without) beats the longest wildcard suffix ("*.example.com", "*-example.com"), which beats "*"; no match uses the URL map's defaults;
- path rules: the longest matching path wins ("/a/*" matches "/a/" and below, never "/a"); an exact path beats a prefix of equal length; no match uses the path matcher's defaults;
- route rules: the lowest priority whose any matchRule matches (path prefix/full/regex/template, header and query parameter matches);
- actions: service, routeAction (weighted backend services, URL rewrite, timeout, retries, ...), urlRedirect; header actions apply from the most specific level (weighted backend, rule, path matcher, map).
Validate reports the configuration errors GCP rejects, and RunTests runs a URL map's tests[] (urlMaps.validate, insert).
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func RedirectCode ¶
RedirectCode maps redirectResponseCode to an HTTP status.
func RunTests ¶
RunTests evaluates m's tests[] and returns the failures. same reports whether two service references name the same resource.
func WalkServices ¶
WalkServices calls fn for every backend reference in m (default services, rule services, weighted backends, mirrors, error services and test expectations) with the request field path, so callers can canonicalise and check them.
Types ¶
type Request ¶
type Request struct {
// Scheme is "http" or "https".
Scheme string
Method string
// Host is the Host header (or :authority), possibly with a port.
Host string
// Path is the URL path (without query).
Path string
// RawQuery is the query string without "?".
RawQuery string
Header http.Header
}
Request is the routing input.
type Result ¶
type Result struct {
// Redirect is set when the request is answered with a redirect.
Redirect *Redirect
// Service is the selected backend service or bucket (as written in
// the URL map, normally a selfLink).
Service string
// Action is the effective route action (nil when none).
Action *compute.HttpRouteAction
// HeaderActions apply in order (most specific first).
HeaderActions []*compute.HttpHeaderAction
// Host and Path are the request host and path after URL rewrites.
Host, Path string
// ErrorPolicies are the custom error response policies that apply,
// most specific first: the matched route or path rule's, the path
// matcher's default, the URL map's default (see ErrorRule).
ErrorPolicies []*compute.CustomErrorResponsePolicy
// PathMatcher names the matched path matcher ("" for map defaults).
PathMatcher string
// RouteRule or PathRule is the rule that matched; neither is set when
// the path matcher's or URL map's defaults apply.
RouteRule *compute.HttpRouteRule
PathRule *compute.PathRule
}
Result is the routing decision.
func (*Result) ErrorRule ¶ added in v0.13.0
func (res *Result) ErrorRule(status int) (*compute.CustomErrorResponsePolicyCustomErrorResponseRule, string)
ErrorRule returns the custom error response rule for a backend's status and the error service that serves its page (FR-LB-012). Each status is checked separately: the first policy in ErrorPolicies with a rule matching it wins, and within a policy a rule naming the exact code ("404") beats one naming its class ("4xx"). It returns nil when no rule lists the status.