@@ -6,26 +6,26 @@ import (
66
77 "github.com/justinas/alice"
88 middlewareapi "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/middleware"
9+ "github.com/oauth2-proxy/oauth2-proxy/v7/pkg/apis/options"
910)
1011
1112type scopeKey string
1213
13−// requestScopeKey uses a typed string to reduce likelihood of clasing
14+// requestScopeKey uses a typed string to reduce likelihood of clashing
1415// with other context keys
1516const requestScopeKey scopeKey = "request-scope"
1617
17−func NewScope() alice.Constructor {
18− return addScope
19−}
20−
21−// addScope injects a new request scope into the request context.
22−func addScope(next http.Handler) http.Handler {
23− return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
24− scope := &middlewareapi.RequestScope{}
25− contextWithScope := context.WithValue(req.Context(), requestScopeKey, scope)
26− requestWithScope := req.WithContext(contextWithScope)
27− next.ServeHTTP(rw, requestWithScope)
28− })
18+func NewScope(opts *options.Options) alice.Constructor {
19+ return func(next http.Handler) http.Handler {
20+ return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
21+ scope := &middlewareapi.RequestScope{
22+ ReverseProxy: opts.ReverseProxy,
23+ }
24+ contextWithScope := context.WithValue(req.Context(), requestScopeKey, scope)
25+ requestWithScope := req.WithContext(contextWithScope)
26+ next.ServeHTTP(rw, requestWithScope)
27+ })
28+ }
2929}
3030
3131// GetRequestScope returns the current request scope from the given request