providers/proxy: add backend_override

Signed-off-by: Jens Langhammer <jens.langhammer@beryju.org>
This commit is contained in:
Jens Langhammer 2022-01-30 21:35:08 +01:00
parent 91d6f572a5
commit 7fd6be5abb
2 changed files with 14 additions and 5 deletions

View File

@ -1,7 +1,8 @@
package application
type ProxyClaims struct {
UserAttributes map[string]interface{} `json:"user_attributes"`
UserAttributes map[string]interface{} `json:"user_attributes"`
BackendOverride string `json:"backend_override"`
}
type Claims struct {

View File

@ -60,7 +60,7 @@ func (a *Application) configureProxy() error {
}
metrics.UpstreamTiming.With(prometheus.Labels{
"outpost_name": a.outpostName,
"upstream_host": u.String(),
"upstream_host": r.URL.Host,
"scheme": r.URL.Scheme,
"method": r.Method,
"path": r.URL.Path,
@ -72,9 +72,17 @@ func (a *Application) configureProxy() error {
}
func (a *Application) proxyModifyRequest(u *url.URL) func(req *http.Request) {
return func(req *http.Request) {
req.URL.Scheme = u.Scheme
req.URL.Host = u.Host
return func(r *http.Request) {
claims, _ := a.getClaims(r)
if claims.Proxy.BackendOverride != "" {
var err error
u, err = url.Parse(claims.Proxy.BackendOverride)
if err != nil {
a.log.WithField("backend_override", claims.Proxy.BackendOverride).WithError(err).Warning("failed parse user backend override")
}
}
r.URL.Scheme = u.Scheme
r.URL.Host = u.Host
}
}