plugin_cond_redirect

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: Apache-2.0 Imports: 5 Imported by: 0

README

Conditional Redirect

Configuration

statusCode: 302 # The http status code of redirection response. default: 302
rules: [] # The rules of redirection
Rule
# When request matches this pattern, will check this rule for redirection.
# Caveat: it must be a regular expression so you should assert beginning and end correctly
sourcePattern: "^/(.*)"
# When set to `true`, sourcePattern will match full url includes host and protocol
withHost: false
# The target url when condition is met.
# It is able to use groups matched by source pattern to do replacement
destinationPattern: "/foo/$1"
# The condition to check.
condition:
  type: header
  name: foo
  pattern: ".*"
Condition
Header
type: header
# When set to true, without this header will also pass the check
optional: true
# Header name 
name: foo
# Pattern to match header value
pattern: ".*"
type: cookie
# When set to true, without this header will also pass the check
optional: true
# Header name 
name: foo
# The path of the cookie, it is not a regular expression
path: ".*"
# Pattern to match header value
pattern: ".*"
Logic
# Only when all children of it passed, it will pass
type: and
# Conditions
children: []
# When any child of it passed, it will pass
type: or
# Conditions
children: []
# Negate the result of condition
type: not
condition:
  type: header
  name: foo
  pattern: ".*"

Documentation

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)

Types

type AndRedirectCondition

type AndRedirectCondition struct {
	Children []RawRedirectCondition `mapstructure:"children"`
}

type ConditionalRedirect

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

func (*ConditionalRedirect) ServeHTTP

func (c *ConditionalRedirect) ServeHTTP(rw http.ResponseWriter, req *http.Request)

type Config

type Config struct {
	StatusCode int            `mapstructure:"statusCode,omitempty"`
	Rules      []RedirectRule `mapstructure:"rules,omitempty"`
}

func CreateConfig

func CreateConfig() *Config

type CookieRedirectCondition

type CookieRedirectCondition struct {
	Name     string `mapstructure:"name"`
	Optional bool   `mapstructure:"optional"`
	Path     string `mapstructure:"path"`
	Pattern  string `mapstructure:"pattern"`
}

type HeaderRedirectCondition

type HeaderRedirectCondition struct {
	Name     string `mapstructure:"name"`
	Optional bool   `mapstructure:"optional"`
	Pattern  string `mapstructure:"pattern"`
}

type NotRedirectCondition

type NotRedirectCondition struct {
	Condition RawRedirectCondition `mapstructure:"condition"`
}

type OrRedirectCondition

type OrRedirectCondition struct {
	Children []RawRedirectCondition `mapstructure:"children"`
}

type RawRedirectCondition

type RawRedirectCondition struct {
	T    string                 `mapstructure:"type"`
	Data map[string]interface{} `mapstructure:",remain"`
}

type RedirectCondition

type RedirectCondition interface {
	// contains filtered or unexported methods
}

type RedirectRule

type RedirectRule struct {
	WithHost           bool                 `mapstructure:"withHost,omitempty"`
	SourcePattern      string               `mapstructure:"sourcePattern"`
	DestinationPattern string               `mapstructure:"destinationPattern"`
	Condition          RawRedirectCondition `mapstructure:"condition"`
}

Jump to

Keyboard shortcuts

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