Documentation
¶
Index ¶
- Constants
- Variables
- type BypassCommand
- type Cache
- func (c Cache) GetBasicAuth(r *http.Request) *Credentials
- func (c Cache) GetCookies(r *http.Request) []*http.Cookie
- func (c Cache) GetQueries(r *http.Request) url.Values
- func (c Cache) GetRemoteIP(r *http.Request) net.IP
- func (c Cache) Release()
- func (c Cache) UpdateCookies(r *http.Request, update UpdateFunc[[]*http.Cookie])
- func (c Cache) UpdateQueries(r *http.Request, update func(url.Values))
- type CheckFunc
- type CheckMatchAll
- type CheckMatchSingle
- type Checker
- type Command
- type CommandHandler
- type Commands
- type Credentials
- type DynamicCommand
- type FieldHandler
- type FieldModifier
- type HashedCrendentials
- type Help
- type ReturningCommand
- type Rule
- type RuleOn
- type Rules
- type StaticCommand
- type StrTuple
- type Tuple
- type UpdateFunc
- type ValidateFunc
Constants ¶
const ( CacheKeyQueries = "queries" CacheKeyCookies = "cookies" CacheKeyRemoteIP = "remote_ip" CacheKeyBasicAuth = "basic_auth" )
const ( CommandRewrite = "rewrite" CommandServe = "serve" CommandProxy = "proxy" CommandRedirect = "redirect" CommandError = "error" CommandRequireBasicAuth = "require_basic_auth" CommandSet = "set" CommandAdd = "add" CommandRemove = "remove" CommandPass = "pass" CommandPassAlt = "bypass" )
const ( FieldHeader = "header" FieldQuery = "query" FieldCookie = "cookie" )
const ( OnHeader = "header" OnQuery = "query" OnCookie = "cookie" OnForm = "form" OnPostForm = "postform" OnMethod = "method" OnPath = "path" OnRemote = "remote" OnBasicAuth = "basic_auth" )
Variables ¶
var ( ErrUnterminatedQuotes = gperr.New("unterminated quotes") ErrUnsupportedEscapeChar = gperr.New("unsupported escape char") ErrUnknownDirective = gperr.New("unknown directive") ErrInvalidArguments = gperr.New("invalid arguments") ErrInvalidOnTarget = gperr.New("invalid `rule.on` target") ErrInvalidCommandSequence = gperr.New("invalid command sequence") ErrInvalidSetTarget = gperr.New("invalid `rule.set` target") ErrExpectNoArg = gperr.Wrap(ErrInvalidArguments, "expect no arg") ErrExpectOneArg = gperr.Wrap(ErrInvalidArguments, "expect 1 arg") ErrExpectTwoArgs = gperr.Wrap(ErrInvalidArguments, "expect 2 args") ErrExpectKVOptionalV = gperr.Wrap(ErrInvalidArguments, "expect 'key' or 'key value'") )
Functions ¶
This section is empty.
Types ¶
type BypassCommand ¶
type BypassCommand struct{}
BypassCommand will skip all the following commands and directly return to reverse proxy.
func (BypassCommand) Handle ¶
func (c BypassCommand) Handle(cached Cache, w http.ResponseWriter, r *http.Request) (proceed bool)
type Cache ¶
Cache is a map of cached values for a request. It prevents the same value from being parsed multiple times.
func (Cache) GetBasicAuth ¶
func (c Cache) GetBasicAuth(r *http.Request) *Credentials
GetBasicAuth returns *Credentials the basic auth username and password. If r does not have basic auth, nil is returned.
func (Cache) GetCookies ¶
GetCookies returns the cookies. If r does not have cookies, an empty slice is returned.
func (Cache) GetQueries ¶
GetQueries returns the queries. If r does not have queries, an empty map is returned.
func (Cache) GetRemoteIP ¶
GetRemoteIP returns the remote ip address. If r.RemoteAddr is not a valid ip address, nil is returned.
func (Cache) Release ¶
func (c Cache) Release()
Release clear the contents of the Cached and returns it to the pool.
func (Cache) UpdateCookies ¶
type CheckMatchAll ¶
type CheckMatchAll []Checker
type CheckMatchSingle ¶
type CheckMatchSingle []Checker
type Command ¶
type Command struct {
// contains filtered or unexported fields
}
func (*Command) MarshalText ¶
type CommandHandler ¶
type Credentials ¶
type DynamicCommand ¶
DynamicCommand will return base on the request and can raed or modify the values.
func (DynamicCommand) Handle ¶
func (c DynamicCommand) Handle(cached Cache, w http.ResponseWriter, r *http.Request) (proceed bool)
type FieldHandler ¶
type FieldHandler struct {
// contains filtered or unexported fields
}
type FieldModifier ¶
type FieldModifier string
const ( ModFieldSet FieldModifier = "set" ModFieldAdd FieldModifier = "add" ModFieldRemove FieldModifier = "remove" )
type HashedCrendentials ¶
func BCryptCrendentials ¶
func BCryptCrendentials(username string, hashedPassword []byte) *HashedCrendentials
func (*HashedCrendentials) Match ¶
func (hc *HashedCrendentials) Match(cred *Credentials) bool
type ReturningCommand ¶
type ReturningCommand http.HandlerFunc
ReturningCommand will run then return immediately.
func (ReturningCommand) Handle ¶
func (c ReturningCommand) Handle(cached Cache, w http.ResponseWriter, r *http.Request) (proceed bool)
type Rule ¶
Rule is a rule for a reverse proxy. It do `Do` when `On` matches.
A rule can have multiple lines of on.
All lines of on must match, but each line can have multiple checks that one match means this line is matched.
type RuleOn ¶
type RuleOn struct {
// contains filtered or unexported fields
}
func (*RuleOn) MarshalText ¶
type Rules ¶
type Rules []*Rule
Example:
proxy.app1.rules: | - name: default do: | rewrite / /index.html serve /var/www/goaccess - name: ws on: | header Connection Upgrade header Upgrade websocket do: bypass proxy.app2.rules: | - name: default do: bypass - name: block POST and PUT on: method POST | method PUT do: error 403 Forbidden
func (Rules) BuildHandler ¶
BuildHandler returns a http.HandlerFunc that implements the rules.
if a bypass rule matches, the request is passed to the upstream and no more rules are executed. if no rule matches, the default rule is executed if no rule matches and default rule is not set, the request is passed to the upstream.
func (Rules) MarshalJSON ¶
type StaticCommand ¶
type StaticCommand http.HandlerFunc
StaticCommand will run then proceed to next command or reverse proxy.
func (StaticCommand) Handle ¶
func (c StaticCommand) Handle(cached Cache, w http.ResponseWriter, r *http.Request) (proceed bool)
type UpdateFunc ¶
type UpdateFunc[T any] func(T) T
Cache is a map of cached values for a request. It prevents the same value from being parsed multiple times.