proxy access log

Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
This commit is contained in:
Jörn Friedrich Dreyer
2021-07-14 13:14:27 +00:00
parent 31918dd44a
commit 1dc7aac6fd
8 changed files with 67 additions and 14 deletions
+14
View File
@@ -20,6 +20,20 @@ var (
ErrUnexpectedConfigError = fmt.Errorf("could not initialize policy-selector for given config")
)
// policyKey serves as key for the routing policy in the context
var policyKey struct{}
// ContextGetPolicy returns the policy if set in the given context.
func ContextGetPolicy(ctx context.Context) string {
u, _ := ctx.Value(policyKey).(string)
return u
}
// ContextSetPolicy stores the selected policy in the context.
func ContextSetPolicy(ctx context.Context, p string) context.Context {
return context.WithValue(ctx, policyKey, p)
}
// Selector is a function which selects a proxy-policy based on the request.
//
// A policy is a random name which identifies a set of proxy-routes:
+1 -6
View File
@@ -146,12 +146,7 @@ func (p *MultiHostReverseProxy) directorSelectionDirector(r *http.Request) {
Str("routeType", string(rt)).
Msg("director found")
p.logger.Info().
Str("method", r.Method).
Str("path", r.Method).
Str("from", r.RemoteAddr).
Msg("access-log")
r = r.WithContext(policy.ContextSetPolicy(r.Context(), pol))
p.Directors[pol][rt][endpoint](r)
return
}