diff --git a/internal/service/policy/service.go b/internal/service/policy/service.go index 6eea0de53af3bee20a05ccb16173f6bad5fd7a04..dbc1d9f5b44b44157debef26d04c3d55266fac0a 100644 --- a/internal/service/policy/service.go +++ b/internal/service/policy/service.go @@ -283,15 +283,14 @@ func (s *Service) queryCacheKey(group, policyName, version string) string { func HeadersMiddleware() func(http.Handler) http.Handler { return func(h http.Handler) http.Handler { return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { - req := r headers := map[string]string{} // get all http headers and add them to a newly initialized request context. for name := range r.Header { headers[name] = r.Header.Get(name) } - ctx := context.WithValue(r.Context(), HeadersKey, headers) - req = r.WithContext(ctx) + ctx := context.WithValue(r.Context(), HeadersKey, headers) //nolint:all + req := r.WithContext(ctx) // call initial handler. h.ServeHTTP(w, req) diff --git a/internal/service/policy/service_test.go b/internal/service/policy/service_test.go index 0cb619a416b445f56ad7140a13b34dc1ed71d814..26167735bf5579024ebd548dfec970d2b9354409 100644 --- a/internal/service/policy/service_test.go +++ b/internal/service/policy/service_test.go @@ -318,7 +318,7 @@ func TestService_Evaluate(t *testing.T) { }, { name: "policy accessing headers is evaluated successfully", - ctx: context.WithValue(context.Background(), policy.HeadersKey, map[string]interface{}{"Authorization": "my-token"}), + ctx: context.WithValue(context.Background(), policy.HeadersKey, map[string]interface{}{"Authorization": "my-token"}), //nolint:all req: testReq(), regocache: &policyfakes.FakeRegoCache{ GetStub: func(key string) (*rego.PreparedEvalQuery, bool) {