routing

package
v5.0.0-...-b98a0e9 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 3, 2024 License: AGPL-3.0 Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultBindingSite = &install.ProxyConfig{
		Binds:       []string{"0.0.0.0:" + runtime.DefaultBindingSitePort},
		TLSConfig:   &install.ProxyConfig_SelfSigned{SelfSigned: &install.TLSSelfSigned{}},
		SSLRedirect: false,
	}
	ConfigPath         = []string{"defaults", "sites"}
	ConfigPathFormated = configx.FormatPath("defaults", "sites")
)

Functions

func DefaultBindOverrideToFlags

func DefaultBindOverrideToFlags() (flags []string)

func EnvOverrideDefaultBind

func EnvOverrideDefaultBind() bool

func GetDefaultSiteURL

func GetDefaultSiteURL(ctx context.Context, sites ...*install.ProxyConfig) string

GetDefaultSiteURL returns the first available bindURL of all available sites

func GetPublicBaseDavSegment

func GetPublicBaseDavSegment(ctx context.Context) string

GetPublicBaseDavSegment returns the segment used to exposed minisites through DAV

func GetPublicBaseUri

func GetPublicBaseUri(ctx context.Context) string

GetPublicBaseUri returns the default public uri

func GetSitesAllowedURLs

func GetSitesAllowedURLs(ctx context.Context) map[string]*url.URL

GetSitesAllowedURLs returns a map of hostname => url for all sites. TODO : this function could switch to a list of specific authorized hostnames

func LoadSites

func LoadSites(ctx context.Context, configOnly ...bool) ([]*install.ProxyConfig, error)

LoadSites returns all sites defined by order of preference : - ENV VARS - YAML CONFIG - INTERNAL CONFIG - If none is found, returns a default value If configOnly is set to true, will only return the ones saved in configs

func RegisterRoute

func RegisterRoute(id, description, defaultURI string, opts ...RouteOption)

RegisterRoute registers a generic route by a unique ID, which URI will be resolved at runtime

func ResolvedURIFromContext

func ResolvedURIFromContext(ctx context.Context) string

ResolvedURIFromContext reads resolved URI from context

func SaveSites

func SaveSites(ctx context.Context, sites []*install.ProxyConfig, user, msg string) error

SaveSites saves a list of sites inside configuration

func SiteContextDiscoveryRoutes

func SiteContextDiscoveryRoutes(ctx context.Context, uriForSameSite ...bool) (map[string][]*url.URL, error)

func SiteFromContext

func SiteFromContext(ctx context.Context, ss []*install.ProxyConfig) (*install.ProxyConfig, *url.URL, bool)

SiteFromContext lookups for siteHash in the context

func StripPrefixKeepSlash

func StripPrefixKeepSlash(prefix string, h http.Handler) http.Handler

StripPrefixKeepSlash returns a handler that serves HTTP requests by removing the given prefix from the request URL's Path (and RawPath if set) and invoking the handler h. StripPrefixKeepSlash handles a request for a path that doesn't begin with prefix by replying with an HTTP 404 not found error. The prefix must match exactly: if the prefix in the request contains escaped characters the reply is also an HTTP 404 not found error.

It differs from http.StripPrefix by keeping a "/" if resulting path is ""

func ToXDS

func ToXDS(site *install.ProxyConfig, upstreamsResolver UpstreamsResolver) (*route.VirtualHost, error)

ToXDS is a WIP implementation for generating XDS configuration from active proxy

Types

type ActiveProxy

type ActiveProxy struct {
	*install.ProxyConfig
	Routes []*ActiveRoute

	// Resolved values
	TLS     string
	TLSCert string
	TLSKey  string
}

func ResolveProxy

func ResolveProxy(proxyConfig *install.ProxyConfig, tlsResolver TLSResolver, rewriteResolver RewritesResolver, upstreamResolver UpstreamsResolver) (*ActiveProxy, error)

ResolveProxy is used with custom resolvers to resolve a proxyConfig to a runtime-usable configuration. Resolvers are implemented by proxies to write correct configuration files

func (*ActiveProxy) Redirects

func (s *ActiveProxy) Redirects() map[string]string

Redirects compute required redirects if SSLRedirect is set

type ActiveRoute

type ActiveRoute struct {
	Path         string
	HeaderMods   []any
	RewriteRules []any
	Upstreams    []any
}

type HandleOption

type HandleOption func(o *HandleOptions)

HandleOption provides functional access for HandleOptions

func WithEnsureTrailing

func WithEnsureTrailing() HandleOption

WithEnsureTrailing will double registration to pattern and pattern+"/" to make sure

func WithRewriteCatchAll

func WithRewriteCatchAll() HandleOption

WithRewriteCatchAll points this handler as catch-all - If request was not handled before, it can be rewritten to this handler resolved pattern and applied

func WithStripPrefix

func WithStripPrefix() HandleOption

WithStripPrefix will wrap the handler **at runtime** with a http.StripPrefix middleware and the resolved URI

type HandleOptions

type HandleOptions struct {
	StripPrefix         bool
	EnsureTrailingSlash bool
	RewriteCatchAll     bool
}

HandleOptions can be used to pass options to the Handle method

type RequestRewriter

type RequestRewriter func(r *http.Request)

type Rewriter

type Rewriter func(req *http.Request, currentRegistrar RouteRegistrar)

type RewritesResolver

type RewritesResolver func(active *ActiveRoute, route Route, rule *install.Rule)

RewritesResolver converts generic rewrite instructions into runtime-usable directives

type Route

type Route interface {
	GetID() string
	GetDescription() string
	GetURI() string
	SupportSubPath() bool
	Endpoint(pattern string) string
	// Handle registers a handler
	Handle(pattern string, handler http.Handler, opts ...HandleOption)
	// Deregister a specific pattern from the current route
	Deregister(pattern string)
}

Route can be seen as a Router for a given route ID

func ListRoutes

func ListRoutes() []Route

ListRoutes returns all declared routes

func RouteById

func RouteById(id string) (Route, bool)

RouteById finds a route by its ID

type RouteOption

type RouteOption func(o *RouteOptions)

RouteOption is the functional access to RouteOptions

func WithCustomResolver

func WithCustomResolver(r func(ctx context.Context) string) RouteOption

WithCustomResolver sets a dynamic resolver to compute default URI value

func WithoutSubPathSupport

func WithoutSubPathSupport() RouteOption

WithoutSubPathSupport declares this route as not being able to be served on a sub-folder URI

type RouteOptions

type RouteOptions struct {
	DefaultURI     string
	CustomResolver func(ctx context.Context) string
	NoSubPath      bool
}

RouteOptions are used to pass options to the route declaration

type RouteRegistrar

type RouteRegistrar interface {
	Route(id string) Route
	DeregisterRoute(id string)
	RegisterRewrite(id string, rewriter Rewriter)
	DeregisterRewrite(id string)
	Patterns(routeIDs ...string) []string
	ApplyRewrites(req *http.Request)
	CanRewriteAndCatchAll(req *http.Request) (b bool)
	IteratePatterns(func(pattern string, handler http.Handler))
}

RouteRegistrar is used to declare routes and their patterns

func NewRouteRegistrar

func NewRouteRegistrar() RouteRegistrar

NewRouteRegistrar creates a RouteRegistrar interface implementation

type TLSResolver

type TLSResolver func(site *ActiveProxy) error

TLSResolver converts TLS config into runtime-usable tls directives

type UpstreamsResolver

type UpstreamsResolver func(string) ([]*url.URL, error)

UpstreamsResolver finds cluster upstreams for a given route URI

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL