Documentation ¶
Overview ¶
Package rp provides a set of utilities to set up and modify behavior of reverse proxies.
Index ¶
- func New(selectors ...*Selector) *httputil.ReverseProxy
- type Matcher
- type Modifier
- type Rule
- func AllOf(rules ...Rule) Rule
- func Always() Rule
- func AnyOf(rules ...Rule) Rule
- func Group(parent Rule, children ...Rule) Rule
- func HasHeader(header string) Rule
- func HasQueryParam(param string) Rule
- func HeaderContains(header string, value string) Rule
- func HostMatches(host string) Rule
- func HostPathIsAt(hostpath string) Rule
- func IPMatches(clientIP string) Rule
- func MethodMatches(method string) Rule
- func PathIsAt(path string) Rule
- func QueryParamContains(param string, value string) Rule
- type SelectOption
- type Selector
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func New ¶
func New(selectors ...*Selector) *httputil.ReverseProxy
New creates a new reverse proxy instance configured with the provided selectors. The selectors determine which rules apply to which incoming requests.
Types ¶
type Matcher ¶ added in v0.2.0
Matcher is a function type that defines the criteria for whether a selector should be applied to a request.
type Modifier ¶ added in v0.2.0
Modifier is a function type that describes how to alter an outgoing request before it's sent.
type Rule ¶
type Rule struct { // Matcher determines if the rule is applicable to a given request. It must be defined for every rule. Matcher Matcher // Modifier is an optional function to alter the outgoing request when the Matcher's criteria is satisfied. Modifier Modifier }
Rule represents the structure for request matching and modification. It consists of a Matcher, which determines if a rule is applicable for a request, and a Modifier, which optionally alters the outgoing request when the rule criteria is met.
func AllOf ¶
AllOf creates a composite rule that matches only if all of the provided rules are satisfied. Modifiers of individual rules are applied in the order they are provided.
func AnyOf ¶
AnyOf creates a composite rule that matches if any of the provided rules are satisfied. The modifier of the first matching rule is used.
func Group ¶ added in v0.2.0
Group creates a composite rule that first checks if the parent rule is satisfied. If the parent is met, it then matches if any of the child rules are met.
func HasHeader ¶
HasHeader creates a rule that matches if the specified header key is present in the request.
func HasQueryParam ¶
HasQueryParam creates a rule that matches if the specified query parameter key exists in the request.
func HeaderContains ¶
HeaderContains creates a rule that matches if the specified header key-value pair exists in the request.
func HostMatches ¶
HostMatches creates a rule that matches a request based on its host.
func HostPathIsAt ¶
HostPathIsAt creates a rule that matches a request based on both its host and path.
func IPMatches ¶
IPMatches creates a rule that matches a request based on the client IP derived from the X-Forwarded-For header.
func MethodMatches ¶
MethodMatches creates a rule that matches a request based on its HTTP method.
func PathIsAt ¶
PathIsAt creates a rule that matches if the request path starts with the specified path. When the rule is satisfied, it also trims the matched path from the outgoing request.
func QueryParamContains ¶
QueryParamContains creates a rule that matches if the specified query parameter key-value pair exists in the request.
type SelectOption ¶
type SelectOption func(*Selector)
SelectOption defines a type for functions that customize a selector.
func WithOIDC ¶
func WithOIDC() SelectOption
WithOIDC constructs a SelectOption that augments a selector to attach an OIDC token as the authorization header for the outgoing request, intended for the target service.
type Selector ¶
type Selector struct {
// contains filtered or unexported fields
}
Selector defines the criteria and actions for selecting and modifying requests in the reverse proxy. It contains a Matcher to decide if the Selector applies to an incoming request, a destination URL to which the request should be sent, and a list of Modifiers to apply to the outgoing request.