Documentation ¶
Overview ¶
Package gobis Mark header as dirty to not forward those headers in the upstream url Useful for middleware when they ask for authorization header fox example
Index ¶
- Constants
- func AddContextValue(req *http.Request, key, val interface{})
- func AddGroups(req *http.Request, groups ...string)
- func DirtHeader(req *http.Request, header string, _ ...string)
- func DirtyHeaders(req *http.Request) *map[string]string
- func ForwardRequest(proxyRoute ProxyRoute, req *http.Request, restPath string)
- func GetMiddlewareName(i interface{}) string
- func Groups(req *http.Request) []string
- func InjectContextValue(req *http.Request, key, inject interface{}) error
- func InterfaceToMap(is ...interface{}) map[string]interface{}
- func IsDirtyHeader(req *http.Request, header string) bool
- func NewDefaultTransport() *http.Transport
- func NewGobisMiddleware(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (func(next http.Handler) http.Handler, error)
- func NewRouteTransport(route ProxyRoute) http.RoundTripper
- func NewRouteTransportWithHttpTransport(route ProxyRoute, httpTransport *http.Transport) http.RoundTripper
- func Path(req *http.Request) string
- func RouteName(req *http.Request) string
- func SetGroups(req *http.Request, groups ...string)
- func SetPath(req *http.Request, path string)
- func SetProtectedHeaders(protectHeaders []string)
- func SetUsername(req *http.Request, username string)
- func UndirtHeader(req *http.Request, header string)
- func Username(req *http.Request) string
- type CreateTransportFunc
- type DefaultHandler
- type DefaultHandlerConfig
- type ErrMiddleware
- type GobisContextKey
- type GobisHandler
- func NewDefaultHandler(config DefaultHandlerConfig, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)
- func NewHandler(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)
- func NewHandlerWithFactory(routes []ProxyRoute, factory RouterFactory) (GobisHandler, error)
- type HostMatcher
- type HostMatchers
- type JsonError
- type MiddlewareChainRoutes
- type MiddlewareConfig
- type MiddlewareContextKey
- type MiddlewareHandler
- type PathMatcher
- func (re PathMatcher) AppPath() string
- func (re PathMatcher) CreateRoutePath(finalPath string) string
- func (re PathMatcher) String() string
- func (re *PathMatcher) UnmarshalCloud(data interface{}) error
- func (re *PathMatcher) UnmarshalJSON(data []byte) error
- func (re *PathMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error
- type ProxyRoute
- func (r ProxyRoute) Check() error
- func (r ProxyRoute) CreateRoutePath(finalPath string) string
- func (r ProxyRoute) PathAsStartPath() string
- func (r ProxyRoute) RequestPath(req *http.Request) string
- func (r ProxyRoute) RouteMatcher() *regexp.Regexp
- func (r *ProxyRoute) UnmarshalJSON(data []byte) error
- func (r *ProxyRoute) UnmarshalYAML(unmarshal func(interface{}) error) error
- func (r ProxyRoute) UpstreamUrl(req *http.Request) *url.URL
- type ProxyRouteBuilder
- func (b *ProxyRouteBuilder) AddHostPassthrough(hostsOrWildcards ...string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) AddRoute(path, url string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) AddRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) AddSubRoute(path, url string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) AddSubRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) Build() []ProxyRoute
- func (b *ProxyRouteBuilder) Finish() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) Parent() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithForwardedHeader(header string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithHttpProxy(httpProxy, httpsProxy string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithInsecureSkipVerify() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithMethods(methods ...string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithMiddlewareParams(params ...interface{}) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithName(name string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithOptionsPassthrough() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithSensitiveHeaders(headers ...string) *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithShowError() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithoutBuffer() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithoutProxy() *ProxyRouteBuilder
- func (b *ProxyRouteBuilder) WithoutProxyHeaders() *ProxyRouteBuilder
- type RouteTransport
- type RouterContextKey
- type RouterFactory
- type RouterFactoryService
- func (r RouterFactoryService) CreateForwardHandler(proxyRoute ProxyRoute) (http.HandlerFunc, error)
- func (r RouterFactoryService) CreateMuxRouter(proxyRoutes []ProxyRoute, startPath string) (*mux.Router, error)
- func (r RouterFactoryService) CreateReverseHandler(proxyRoute ProxyRoute) (http.Handler, error)
Constants ¶
const ( XForwardedProto = "X-Forwarded-Proto" XForwardedFor = "X-Forwarded-For" XForwardedHost = "X-Forwarded-Host" XForwardedServer = "X-Forwarded-Server" )
const ( GobisHeaderName = "X-Gobis-Forward" XGobisUsername = "X-Gobis-Username" XGobisGroups = "X-Gobis-Groups" )
const (
PathRegex = "(?i)^((/[^/\\*]*)*)(/((\\*){1,2}))?$"
)
Variables ¶
This section is empty.
Functions ¶
func AddContextValue ¶
AddContextValue Add a context value to a http request without having to override request by yourself
func DirtHeader ¶
DirtHeader Mark a http header as dirty Useful to prevent some headers added and used by middleware to not be sent to upstream if oldValue is not empty it will make proxy rewrite header with this value
func DirtyHeaders ¶
DirtyHeaders Retrieve all http headers marked as dirty
func ForwardRequest ¶
func ForwardRequest(proxyRoute ProxyRoute, req *http.Request, restPath string)
func GetMiddlewareName ¶
func GetMiddlewareName(i interface{}) string
func InjectContextValue ¶
InjectContextValue Inject a value from a request context to an interface This is the same behaviour as json.Unmarshal
func InterfaceToMap ¶
func InterfaceToMap(is ...interface{}) map[string]interface{}
func IsDirtyHeader ¶
IsDirtyHeader Return true if a http header is marked as dirty
func NewDefaultTransport ¶
func NewGobisMiddleware ¶
func NewGobisMiddleware(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (func(next http.Handler) http.Handler, error)
func NewRouteTransport ¶
func NewRouteTransport(route ProxyRoute) http.RoundTripper
func NewRouteTransportWithHttpTransport ¶
func NewRouteTransportWithHttpTransport(route ProxyRoute, httpTransport *http.Transport) http.RoundTripper
func SetPath ¶
SetPath Set the rest of the path from a request url to his context (used by router factory)
func SetProtectedHeaders ¶
func SetProtectedHeaders(protectHeaders []string)
func SetUsername ¶
SetUsername Set the username to a request context
func UndirtHeader ¶
UndirtHeader Remove a http header from the list of dirty header
Types ¶
type CreateTransportFunc ¶
type CreateTransportFunc func(ProxyRoute) http.RoundTripper
type DefaultHandler ¶
type DefaultHandler struct {
// contains filtered or unexported fields
}
func (DefaultHandler) GetServerAddr ¶
func (h DefaultHandler) GetServerAddr() string
func (*DefaultHandler) ServeHTTP ¶
func (h *DefaultHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)
type DefaultHandlerConfig ¶
type DefaultHandlerConfig struct { // List of routes Routes []ProxyRoute `json:"routes" yaml:"routes"` // List of headers which cannot be removed by `sensitive_headers` ProtectedHeaders []string `json:"protected_headers" yaml:"protected_headers"` // Set the path where all path from routes should start (e.g.: if set to `/root` request for the next routes will be localhost/root/app) StartPath string `json:"start_path" yaml:"start_path"` }
type ErrMiddleware ¶
type ErrMiddleware string
func (ErrMiddleware) Error ¶
func (e ErrMiddleware) Error() string
type GobisContextKey ¶
type GobisContextKey int
type GobisHandler ¶
type GobisHandler interface { GetServerAddr() string ServeHTTP(http.ResponseWriter, *http.Request) }
func NewDefaultHandler ¶
func NewDefaultHandler(config DefaultHandlerConfig, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)
func NewHandler ¶
func NewHandler(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)
func NewHandlerWithFactory ¶ added in v1.4.1
func NewHandlerWithFactory(routes []ProxyRoute, factory RouterFactory) (GobisHandler, error)
type HostMatcher ¶
func NewHostMatcher ¶
func NewHostMatcher(hostOrWildcard string) *HostMatcher
func (HostMatcher) String ¶
func (re HostMatcher) String() string
func (*HostMatcher) UnmarshalJSON ¶
func (re *HostMatcher) UnmarshalJSON(data []byte) error
func (*HostMatcher) UnmarshalYAML ¶
func (re *HostMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error
type HostMatchers ¶
type HostMatchers []*HostMatcher
func (HostMatchers) Match ¶
func (m HostMatchers) Match(s string) bool
type MiddlewareChainRoutes ¶
type MiddlewareChainRoutes struct {
// contains filtered or unexported fields
}
func NewMiddlewareChainRoutes ¶
func NewMiddlewareChainRoutes(routerFactory RouterFactory) *MiddlewareChainRoutes
func (MiddlewareChainRoutes) Handler ¶
func (m MiddlewareChainRoutes) Handler(route ProxyRoute, params interface{}, next http.Handler) (http.Handler, error)
func (MiddlewareChainRoutes) Schema ¶
func (m MiddlewareChainRoutes) Schema() interface{}
type MiddlewareConfig ¶
type MiddlewareConfig struct { // List of routes Routes []ProxyRoute `json:"routes" yaml:"routes"` // Set the path where all path from routes should start (e.g.: if set to `/root` request for the next routes will be localhost/root/app) StartPath string `json:"start_path" yaml:"start_path"` }
type MiddlewareContextKey ¶
type MiddlewareContextKey int
const ( GroupContextKey MiddlewareContextKey = iota UsernameContextKey )
type MiddlewareHandler ¶
type PathMatcher ¶
type PathMatcher struct {
// contains filtered or unexported fields
}
func NewPathMatcher ¶
func NewPathMatcher(path string) *PathMatcher
func (PathMatcher) AppPath ¶
func (re PathMatcher) AppPath() string
func (PathMatcher) CreateRoutePath ¶
func (re PathMatcher) CreateRoutePath(finalPath string) string
func (PathMatcher) String ¶
func (re PathMatcher) String() string
func (*PathMatcher) UnmarshalCloud ¶ added in v1.1.0
func (re *PathMatcher) UnmarshalCloud(data interface{}) error
func (*PathMatcher) UnmarshalJSON ¶
func (re *PathMatcher) UnmarshalJSON(data []byte) error
func (*PathMatcher) UnmarshalYAML ¶
func (re *PathMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error
type ProxyRoute ¶
type ProxyRoute struct { // Name of your routes Name string `json:"name" yaml:"name"` // Path which gobis handler should listen to // You can use globs: // - appending /* will only make requests available in first level of upstream // - appending /** will pass everything to upstream // e.g.: /app/** Path *PathMatcher `json:"path" yaml:"path"` // Url Upstream url where all request will be redirected (if ForwardedHeader option not set) // Query parameters can be passed, e.g.: http://localhost?param=1 // User and password are given as basic auth too (this is not recommended to use it), e.g.: http://user:password@localhost // Can be empty if ForwardedHeader is set // This is ignored if ForwardHandler is set Url string `json:"url" yaml:"url"` // ForwardedHeader If set upstream url will be taken from the value of this header inside the received request // Url option will be used for the router to match host and path (if not empty) found in value of this header and host and path found in url (If NoUrlMatch is false) // this useful, for example, to create a cloud foundry routes service: https://docs.cloudfoundry.org/services/route-services.html ForwardedHeader string `json:"forwarded_header" yaml:"forwarded_header"` // SensitiveHeaders List of headers which should not be sent to upstream SensitiveHeaders []string `json:"sensitive_headers" yaml:"sensitive_headers"` // Methods List of http methods allowed (Default: all methods are accepted) Methods []string `json:"methods" yaml:"methods"` // HttpProxy An url to a http proxy to make requests to upstream pass to this HttpProxy string `json:"http_proxy" yaml:"http_proxy"` // HttpsProxy An url to a https proxy to make requests to upstream pass to this HttpsProxy string `json:"https_proxy" yaml:"https_proxy"` // NoProxy Force to never use proxy even proxy from environment variables NoProxy bool `json:"no_proxy" yaml:"no_proxy"` // NoBuffer Responses from upstream are buffered by default, it can be issue when sending big files // Set to true to stream response NoBuffer bool `json:"no_buffer" yaml:"no_buffer"` // RemoveProxyHeaders Set to true to not send X-Forwarded-* headers to upstream RemoveProxyHeaders bool `json:"remove_proxy_headers" yaml:"remove_proxy_headers"` // InsecureSkipVerify Set to true to not check ssl certificates from upstream (not really recommended) InsecureSkipVerify bool `json:"insecure_skip_verify" yaml:"insecure_skip_verify"` // MiddlewareParams It was made to pass arbitrary params to use it after in gobis middlewares // This can be a structure (to set them programmatically) or a map[string]interface{} (to set them from a config file) MiddlewareParams interface{} `json:"middleware_params" yaml:"middleware_params"` // ShowError Set to true to see errors on web page when there is a panic error on gobis ShowError bool `json:"show_error" yaml:"show_error"` // UseFullPath Set to true to use full path // e.g.: path=/metrics/** and request=/metrics/foo this will be redirected to /metrics/foo on upstream instead of /foo UseFullPath bool `json:"use_full_path" yaml:"use_full_path"` // Routes Chain others routes in a routes Routes []ProxyRoute `json:"routes" yaml:"routes"` // ForwardHandler Set a handler to use to forward request to this handler when using gobis programmatically ForwardHandler http.Handler `json:"-" yaml:"-"` // OptionsPassthrough Will forward directly to proxied route OPTIONS method without using middlewares OptionsPassthrough bool `json:"options_passthrough" yaml:"options_passthrough"` // HostsPassthrough Will forward directly to proxied route without using middlewares when http header host given match one of host in this list // Wildcard are allowed // E.g.: - *.my.passthroughurl.com -> this will allow all routes matching this wildcard to passthrough middleware // **Warning**: host header can be forged by user, this may be a security issue if not used properly. HostsPassthrough HostMatchers `json:"hosts_passthrough" yaml:"hosts_passthrough"` }
func (ProxyRoute) Check ¶
func (r ProxyRoute) Check() error
func (ProxyRoute) CreateRoutePath ¶
func (r ProxyRoute) CreateRoutePath(finalPath string) string
func (ProxyRoute) PathAsStartPath ¶
func (r ProxyRoute) PathAsStartPath() string
func (ProxyRoute) RequestPath ¶
func (r ProxyRoute) RequestPath(req *http.Request) string
func (ProxyRoute) RouteMatcher ¶
func (r ProxyRoute) RouteMatcher() *regexp.Regexp
func (*ProxyRoute) UnmarshalJSON ¶
func (r *ProxyRoute) UnmarshalJSON(data []byte) error
func (*ProxyRoute) UnmarshalYAML ¶
func (r *ProxyRoute) UnmarshalYAML(unmarshal func(interface{}) error) error
func (ProxyRoute) UpstreamUrl ¶
func (r ProxyRoute) UpstreamUrl(req *http.Request) *url.URL
type ProxyRouteBuilder ¶
type ProxyRouteBuilder struct {
// contains filtered or unexported fields
}
func Builder ¶
func Builder() *ProxyRouteBuilder
func (*ProxyRouteBuilder) AddHostPassthrough ¶
func (b *ProxyRouteBuilder) AddHostPassthrough(hostsOrWildcards ...string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) AddRoute ¶
func (b *ProxyRouteBuilder) AddRoute(path, url string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) AddRouteHandler ¶
func (b *ProxyRouteBuilder) AddRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder
func (*ProxyRouteBuilder) AddSubRoute ¶
func (b *ProxyRouteBuilder) AddSubRoute(path, url string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) AddSubRouteHandler ¶
func (b *ProxyRouteBuilder) AddSubRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder
func (*ProxyRouteBuilder) Build ¶
func (b *ProxyRouteBuilder) Build() []ProxyRoute
func (*ProxyRouteBuilder) Finish ¶
func (b *ProxyRouteBuilder) Finish() *ProxyRouteBuilder
func (*ProxyRouteBuilder) Parent ¶
func (b *ProxyRouteBuilder) Parent() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithForwardedHeader ¶
func (b *ProxyRouteBuilder) WithForwardedHeader(header string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithHttpProxy ¶
func (b *ProxyRouteBuilder) WithHttpProxy(httpProxy, httpsProxy string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithInsecureSkipVerify ¶
func (b *ProxyRouteBuilder) WithInsecureSkipVerify() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithMethods ¶
func (b *ProxyRouteBuilder) WithMethods(methods ...string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithMiddlewareParams ¶
func (b *ProxyRouteBuilder) WithMiddlewareParams(params ...interface{}) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithName ¶
func (b *ProxyRouteBuilder) WithName(name string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithOptionsPassthrough ¶
func (b *ProxyRouteBuilder) WithOptionsPassthrough() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithSensitiveHeaders ¶
func (b *ProxyRouteBuilder) WithSensitiveHeaders(headers ...string) *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithShowError ¶
func (b *ProxyRouteBuilder) WithShowError() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithoutBuffer ¶
func (b *ProxyRouteBuilder) WithoutBuffer() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithoutProxy ¶
func (b *ProxyRouteBuilder) WithoutProxy() *ProxyRouteBuilder
func (*ProxyRouteBuilder) WithoutProxyHeaders ¶
func (b *ProxyRouteBuilder) WithoutProxyHeaders() *ProxyRouteBuilder
type RouteTransport ¶
type RouteTransport struct {
// contains filtered or unexported fields
}
func (*RouteTransport) InitHttpTransport ¶
func (r *RouteTransport) InitHttpTransport()
func (*RouteTransport) ProxyFromRouteOrEnv ¶
func (*RouteTransport) TransformRequest ¶
func (r *RouteTransport) TransformRequest(req *http.Request)
type RouterContextKey ¶
type RouterContextKey int
type RouterFactory ¶
type RouterFactory interface { CreateMuxRouter([]ProxyRoute, string) (*mux.Router, error) CreateForwardHandler(ProxyRoute) (http.HandlerFunc, error) CreateReverseHandler(ProxyRoute) (http.Handler, error) }
func NewRouterFactory ¶
func NewRouterFactory(middlewareHandlers ...MiddlewareHandler) RouterFactory
func NewRouterFactoryWithMuxRouter ¶
func NewRouterFactoryWithMuxRouter(muxRouterOption func() *mux.Router, middlewares ...MiddlewareHandler) RouterFactory
type RouterFactoryService ¶
type RouterFactoryService struct { CreateTransportFunc CreateTransportFunc MiddlewareHandlers []MiddlewareHandler // contains filtered or unexported fields }
func (RouterFactoryService) CreateForwardHandler ¶
func (r RouterFactoryService) CreateForwardHandler(proxyRoute ProxyRoute) (http.HandlerFunc, error)
func (RouterFactoryService) CreateMuxRouter ¶
func (r RouterFactoryService) CreateMuxRouter(proxyRoutes []ProxyRoute, startPath string) (*mux.Router, error)
func (RouterFactoryService) CreateReverseHandler ¶
func (r RouterFactoryService) CreateReverseHandler(proxyRoute ProxyRoute) (http.Handler, error)