multiplexer_proxy

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2023 License: Apache-2.0 Imports: 10 Imported by: 0

README

Reverse proxy based on a header's value

(This code is based on the code (and takes inspiration) from: https://github.com/vidosits/header-pattern-proxy) This middleware can be used to reverse proxy a request based on a headers value, e.g. based on the value of X-Forwarded-User from something like thomseddon/traefik-forward-auth.

Compared to the original setup, this version allows more complex, dynamic target URLs, partially based on the original URL and the header field. The code also contains better caching, for better performance.

Configuration

Static:

Production:

[pilot]
  token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

[experimental]
  [experimental.plugins]
    [experimental.plugins.my-plugin-name]
      moduleName = "github.com/dobots/multiplexer-proxy
      version = "v1.0.0"

or if you're using devMode:

[pilot]
  token = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
  
[experimental.devPlugin]
  goPath = "/plugins/go"
  moduleName = "github.com/dobots/multiplexer-proxy"
  # Plugin will be loaded from '/plugins/go/src/github.com/dobots/multiplexer-proxy'
Dynamic:

Production:

[http]
  [http.middlewares]
    [http.middlewares.my-middleware-name.plugin.my-plugin-name]
      header  = "X-Forwarded-User"
      target_match = "^([^.]+).(.*)$"         #If not matching, keep original URL
      target_replace = "$1-${header}.$2"      #Normal (go-lang) regexp rules, ${header} is replaced by the matched header value (URLEncoded)

  [http.routers]
    [http.routers.my-router-name]
      entryPoints = ["websecure"]
      rule = "Host(`my-service-name.domain.tld`)"
      middlewares = ["traefik-forward-auth@docker", "my-middleware-name@file"]
      
      # if no matches are found this is the service that we forward the request to
      service = "noop@internal"
      
      [http.routers.my-router-name.tls]
        certResolver = "letsencrypt"

or if you're using devMode:

[http]
  [http.middlewares]
    [http.middlewares.my-middleware-name.plugin.dev]
      header  = "X-Forwarded-User"
      target_match = "^([^.]+).(.*)$"         #If not matching, keep original URL
      target_replace = "$1-${header}.$2"      #Normal (go-lang) regexp rules, ${header} is replaced by the matched header value (URLEncoded)

  [http.routers]
    [http.routers.my-router-name]
      entryPoints = ["websecure"]
      rule = "Host(`my-service-name.domain.tld`)"
      middlewares = ["traefik-forward-auth@docker", "my-middleware-name@file"]
      
      # if no matches are found this is the service that we forward the request to
      service = "noop@internal"
      
      [http.routers.my-router-name.tls]
        certResolver = "letsencrypt"

License

This software is released under the Apache 2.0 License.

Documentation

Overview

Package header_pattern_proxy

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func New

func New(ctx context.Context, next http.Handler, config *Config, name string) (http.Handler, error)

New created a new SiteProxy plugin.

Types

type Config

type Config struct {
	Header        string `json:"header,omitempty" yaml:"Header" mapstructure:"Header" default:"X-Forward-User"`
	TargetMatch   string `json:"target_match,omitempty" yaml:"Target_match" mapstructure:"Target_match" default:"^(.*)$"`
	TargetReplace string `json:"target_replace,omitempty" yaml:"Target_replace" mapstructure:"Target_replace" default:"test.$1"`
}

Config the plugin configuration.

func CreateConfig

func CreateConfig() *Config

CreateConfig creates the default plugin configuration.

type SiteProxy

type SiteProxy struct {
	// contains filtered or unexported fields
}

func (*SiteProxy) ServeHTTP

func (a *SiteProxy) ServeHTTP(rw http.ResponseWriter, req *http.Request)

Jump to

Keyboard shortcuts

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