gobis: github.com/orange-cloudfoundry/gobis Index | Files | Directories

package gobis

import "github.com/orange-cloudfoundry/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


Package Files

builder.go ctx_dirty_headers.go ctx_helper.go ctx_middlewares.go ctx_router.go default_handler.go handler.go matcher.go middleware.go middleware_chain.go proxy_route.go route_transport.go router_factory.go utils.go


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}))?$"

func AddContextValue Uses

func AddContextValue(req *http.Request, key, val interface{})

Add a context value to an http request without having to override request by yourself

func AddGroups Uses

func AddGroups(req *http.Request, groups ...string)

add groups to a request context

func DirtHeader Uses

func DirtHeader(req *http.Request, header string, oldValue ...string)

Mark an 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 Uses

func DirtyHeaders(req *http.Request) *map[string]string

Retrieve all http headers marked as dirty

func ForwardRequest Uses

func ForwardRequest(proxyRoute ProxyRoute, req *http.Request, restPath string)

func GetMiddlewareName Uses

func GetMiddlewareName(i interface{}) string

func Groups Uses

func Groups(req *http.Request) []string

retrieve groups from request context

func InjectContextValue Uses

func InjectContextValue(req *http.Request, key, inject interface{}) error

Inject a value from a request context to an interface This is the same behaviour as json.Unmarshal

func InterfaceToMap Uses

func InterfaceToMap(is ...interface{}) map[string]interface{}

func IsDirtyHeader Uses

func IsDirtyHeader(req *http.Request, header string) bool

Return true if an http header is marked as dirty

func NewDefaultTransport Uses

func NewDefaultTransport() *http.Transport

func NewGobisMiddleware Uses

func NewGobisMiddleware(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (func(next http.Handler) http.Handler, error)

func NewRouteTransport Uses

func NewRouteTransport(route ProxyRoute) http.RoundTripper

func NewRouteTransportWithHttpTransport Uses

func NewRouteTransportWithHttpTransport(route ProxyRoute, httpTransport *http.Transport) http.RoundTripper

func Path Uses

func Path(req *http.Request) string

Retrieve rest of the path from a request url to his context

func RouteName Uses

func RouteName(req *http.Request) string

Retrieve routes name used in this request

func SetGroups Uses

func SetGroups(req *http.Request, groups ...string)

add groups to a request context this call AddGroups, it's simply for UX

func SetPath Uses

func SetPath(req *http.Request, path string)

Set the rest of the path from a request url to his context (used by router factory)

func SetProtectedHeaders Uses

func SetProtectedHeaders(protectHeaders []string)

func SetUsername Uses

func SetUsername(req *http.Request, username string)

Set the username to a request context

func UndirtHeader Uses

func UndirtHeader(req *http.Request, header string)

Remove an http header from the list of dirty header

func Username Uses

func Username(req *http.Request) string

Retrieve username from a request context

type CreateTransportFunc Uses

type CreateTransportFunc func(ProxyRoute) http.RoundTripper

type DefaultHandler Uses

type DefaultHandler struct {
    // contains filtered or unexported fields

func (DefaultHandler) GetServerAddr Uses

func (h DefaultHandler) GetServerAddr() string

func (*DefaultHandler) ServeHTTP Uses

func (h *DefaultHandler) ServeHTTP(w http.ResponseWriter, req *http.Request)

type DefaultHandlerConfig Uses

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 Uses

type ErrMiddleware string

func (ErrMiddleware) Error Uses

func (e ErrMiddleware) Error() string

type GobisContextKey Uses

type GobisContextKey int

type GobisHandler Uses

type GobisHandler interface {
    GetServerAddr() string
    ServeHTTP(http.ResponseWriter, *http.Request)

func NewDefaultHandler Uses

func NewDefaultHandler(config DefaultHandlerConfig, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)

func NewHandler Uses

func NewHandler(routes []ProxyRoute, middlewareHandlers ...MiddlewareHandler) (GobisHandler, error)

func NewHandlerWithFactory Uses

func NewHandlerWithFactory(routes []ProxyRoute, factory RouterFactory) (GobisHandler, error)

type HostMatcher Uses

type HostMatcher struct {
    // contains filtered or unexported fields

func NewHostMatcher Uses

func NewHostMatcher(hostOrWildcard string) *HostMatcher

func (HostMatcher) String Uses

func (re HostMatcher) String() string

func (*HostMatcher) UnmarshalJSON Uses

func (re *HostMatcher) UnmarshalJSON(data []byte) error

func (*HostMatcher) UnmarshalYAML Uses

func (re *HostMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error

type HostMatchers Uses

type HostMatchers []*HostMatcher

func (HostMatchers) Match Uses

func (m HostMatchers) Match(s string) bool

type JsonError Uses

type JsonError struct {
    Status    int    `json:"status"`
    Title     string `json:"title"`
    Details   string `json:"details"`
    RouteName string `json:"route_name"`

type MiddlewareChainRoutes Uses

type MiddlewareChainRoutes struct {
    // contains filtered or unexported fields

func NewMiddlewareChainRoutes Uses

func NewMiddlewareChainRoutes(routerFactory RouterFactory) *MiddlewareChainRoutes

func (MiddlewareChainRoutes) Handler Uses

func (m MiddlewareChainRoutes) Handler(route ProxyRoute, params interface{}, next http.Handler) (http.Handler, error)

func (MiddlewareChainRoutes) Schema Uses

func (m MiddlewareChainRoutes) Schema() interface{}

type MiddlewareConfig Uses

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 Uses

type MiddlewareContextKey int
const (
    GroupContextKey MiddlewareContextKey = iota

type MiddlewareHandler Uses

type MiddlewareHandler interface {
    Handler(route ProxyRoute, params interface{}, next http.Handler) (http.Handler, error)
    Schema() interface{}

type PathMatcher Uses

type PathMatcher struct {
    // contains filtered or unexported fields

func NewPathMatcher Uses

func NewPathMatcher(path string) *PathMatcher

func (PathMatcher) AppPath Uses

func (re PathMatcher) AppPath() string

func (PathMatcher) CreateRoutePath Uses

func (re PathMatcher) CreateRoutePath(finalPath string) string

func (PathMatcher) String Uses

func (re PathMatcher) String() string

func (*PathMatcher) UnmarshalCloud Uses

func (re *PathMatcher) UnmarshalCloud(data interface{}) error

func (*PathMatcher) UnmarshalJSON Uses

func (re *PathMatcher) UnmarshalJSON(data []byte) error

func (*PathMatcher) UnmarshalYAML Uses

func (re *PathMatcher) UnmarshalYAML(unmarshal func(interface{}) error) error

type ProxyRoute Uses

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"`
    // 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"`
    // If set upstream url will be took 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"`
    // List of headers which should not be sent to upstream
    SensitiveHeaders []string `json:"sensitive_headers" yaml:"sensitive_headers"`
    // List of http methods allowed (Default: all methods are accepted)
    Methods []string `json:"methods" yaml:"methods"`
    // An url to an http proxy to make requests to upstream pass to this
    HttpProxy string `json:"http_proxy" yaml:"http_proxy"`
    // An url to an https proxy to make requests to upstream pass to this
    HttpsProxy string `json:"https_proxy" yaml:"https_proxy"`
    // Force to never use proxy even proxy from environment variables
    NoProxy bool `json:"no_proxy" yaml:"no_proxy"`
    // By default response from upstream are buffered, it can be issue when sending big files
    // Set to true to stream response
    NoBuffer bool `json:"no_buffer" yaml:"no_buffer"`
    // Set to true to not send X-Forwarded-* headers to upstream
    RemoveProxyHeaders bool `json:"remove_proxy_headers" yaml:"remove_proxy_headers"`
    // Set to true to not check ssl certificates from upstream (not really recommended)
    InsecureSkipVerify bool `json:"insecure_skip_verify" yaml:"insecure_skip_verify"`
    // 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"`
    // 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"`
    // 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"`
    // Chain others routes in a routes
    Routes []ProxyRoute `json:"routes" yaml:"routes"`
    // Set an handler to use to forward request to this handler when using gobis programmatically
    ForwardHandler http.Handler `json:"-" yaml:"-"`
    // Will forward directly to proxified route OPTIONS method without using middlewares
    OptionsPassthrough bool `json:"options_passthrough" yaml:"options_passthrough"`
    // Will forward directly to proxified route without using middlewares when http header host given match one of host in this list
    // Wilcard are allowed
    // E.g.: - *.my.passthroughurl.com -> this will allow all routes matching this wilcard 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 Uses

func (r ProxyRoute) Check() error

func (ProxyRoute) CreateRoutePath Uses

func (r ProxyRoute) CreateRoutePath(finalPath string) string

func (ProxyRoute) PathAsStartPath Uses

func (r ProxyRoute) PathAsStartPath() string

func (ProxyRoute) RequestPath Uses

func (r ProxyRoute) RequestPath(req *http.Request) string

func (ProxyRoute) RouteMatcher Uses

func (r ProxyRoute) RouteMatcher() *regexp.Regexp

func (*ProxyRoute) UnmarshalJSON Uses

func (r *ProxyRoute) UnmarshalJSON(data []byte) error

func (*ProxyRoute) UnmarshalYAML Uses

func (r *ProxyRoute) UnmarshalYAML(unmarshal func(interface{}) error) error

func (ProxyRoute) UpstreamUrl Uses

func (r ProxyRoute) UpstreamUrl(req *http.Request) *url.URL

type ProxyRouteBuilder Uses

type ProxyRouteBuilder struct {
    // contains filtered or unexported fields

func Builder Uses

func Builder() *ProxyRouteBuilder

func (*ProxyRouteBuilder) AddHostPassthrough Uses

func (b *ProxyRouteBuilder) AddHostPassthrough(hostsOrWildcards ...string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) AddRoute Uses

func (b *ProxyRouteBuilder) AddRoute(path, url string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) AddRouteHandler Uses

func (b *ProxyRouteBuilder) AddRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder

func (*ProxyRouteBuilder) AddSubRoute Uses

func (b *ProxyRouteBuilder) AddSubRoute(path, url string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) AddSubRouteHandler Uses

func (b *ProxyRouteBuilder) AddSubRouteHandler(path string, forwardHandler http.Handler) *ProxyRouteBuilder

func (*ProxyRouteBuilder) Build Uses

func (b *ProxyRouteBuilder) Build() []ProxyRoute

func (*ProxyRouteBuilder) Finish Uses

func (b *ProxyRouteBuilder) Finish() *ProxyRouteBuilder

func (*ProxyRouteBuilder) Parent Uses

func (b *ProxyRouteBuilder) Parent() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithForwardedHeader Uses

func (b *ProxyRouteBuilder) WithForwardedHeader(header string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithHttpProxy Uses

func (b *ProxyRouteBuilder) WithHttpProxy(httpProxy, httpsProxy string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithInsecureSkipVerify Uses

func (b *ProxyRouteBuilder) WithInsecureSkipVerify() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithMethods Uses

func (b *ProxyRouteBuilder) WithMethods(methods ...string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithMiddlewareParams Uses

func (b *ProxyRouteBuilder) WithMiddlewareParams(params ...interface{}) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithName Uses

func (b *ProxyRouteBuilder) WithName(name string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithOptionsPassthrough Uses

func (b *ProxyRouteBuilder) WithOptionsPassthrough() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithSensitiveHeaders Uses

func (b *ProxyRouteBuilder) WithSensitiveHeaders(headers ...string) *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithShowError Uses

func (b *ProxyRouteBuilder) WithShowError() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithoutBuffer Uses

func (b *ProxyRouteBuilder) WithoutBuffer() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithoutProxy Uses

func (b *ProxyRouteBuilder) WithoutProxy() *ProxyRouteBuilder

func (*ProxyRouteBuilder) WithoutProxyHeaders Uses

func (b *ProxyRouteBuilder) WithoutProxyHeaders() *ProxyRouteBuilder

type RouteTransport Uses

type RouteTransport struct {
    // contains filtered or unexported fields

func (*RouteTransport) InitHttpTransport Uses

func (r *RouteTransport) InitHttpTransport()

func (*RouteTransport) ProxyFromRouteOrEnv Uses

func (r *RouteTransport) ProxyFromRouteOrEnv(req *http.Request) (*url.URL, error)

func (*RouteTransport) RoundTrip Uses

func (r *RouteTransport) RoundTrip(req *http.Request) (*http.Response, error)

func (*RouteTransport) TransformRequest Uses

func (r *RouteTransport) TransformRequest(req *http.Request)

type RouterContextKey Uses

type RouterContextKey int

type RouterFactory Uses

type RouterFactory interface {
    CreateMuxRouter([]ProxyRoute, string) (*mux.Router, error)
    CreateForwardHandler(ProxyRoute) (http.HandlerFunc, error)
    CreateReverseHandler(ProxyRoute) (http.Handler, error)

func NewRouterFactory Uses

func NewRouterFactory(middlewareHandlers ...MiddlewareHandler) RouterFactory

func NewRouterFactoryWithMuxRouter Uses

func NewRouterFactoryWithMuxRouter(muxRouterOption func() *mux.Router, middlewares ...MiddlewareHandler) RouterFactory

type RouterFactoryService Uses

type RouterFactoryService struct {
    CreateTransportFunc CreateTransportFunc
    MiddlewareHandlers  []MiddlewareHandler
    // contains filtered or unexported fields

func (RouterFactoryService) CreateForwardHandler Uses

func (r RouterFactoryService) CreateForwardHandler(proxyRoute ProxyRoute) (http.HandlerFunc, error)

func (RouterFactoryService) CreateMuxRouter Uses

func (r RouterFactoryService) CreateMuxRouter(proxyRoutes []ProxyRoute, startPath string) (*mux.Router, error)

func (RouterFactoryService) CreateReverseHandler Uses

func (r RouterFactoryService) CreateReverseHandler(proxyRoute ProxyRoute) (http.Handler, error)



Package gobis imports 20 packages (graph) and is imported by 22 packages. Updated 2019-07-29. Refresh now. Tools for package owners.