Skip to content

Commit

Permalink
Pass context through to external requests
Browse files Browse the repository at this point in the history
Enables proper tracing through Jaeger etc
  • Loading branch information
ptescher committed Jan 5, 2021
1 parent 033f543 commit b7fa48f
Show file tree
Hide file tree
Showing 7 changed files with 9 additions and 8 deletions.
5 changes: 3 additions & 2 deletions pipeline/authn/authenticator_cookie_session.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,12 @@ func forwardRequestToSessionStore(r *http.Request, checkSessionURL string, prese
reqUrl.Path = r.URL.Path
}

res, err := http.DefaultClient.Do(&http.Request{
req := http.Request{
Method: r.Method,
URL: reqUrl,
Header: r.Header,
})
}
res, err := http.DefaultClient.Do(req.WithContext(r.Context()))
if err != nil {
return nil, helper.ErrForbidden.WithReason(err.Error()).WithTrace(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/authn/authenticator_oauth2_client_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ func (a *AuthenticatorOAuth2ClientCredentials) Authenticate(r *http.Request, ses
}

token, err := c.Token(context.WithValue(
context.Background(),
r.Context(),
oauth2.HTTPClient,
c.Client,
))
Expand Down
2 changes: 1 addition & 1 deletion pipeline/authn/authenticator_oauth2_introspection.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (a *AuthenticatorOAuth2Introspection) Authenticate(r *http.Request, session
}
// set/override the content-type header
introspectReq.Header.Set("Content-Type", "application/x-www-form-urlencoded")
resp, err := a.client.Do(introspectReq)
resp, err := a.client.Do(introspectReq.WithContext(r.Context()))
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/authz/keto_engine_acp_ory.go
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ func (a *AuthorizerKetoEngineACPORY) Authorize(r *http.Request, session *authn.A
}
req.Header.Add("Content-Type", "application/json")

res, err := a.client.Do(req)
res, err := a.client.Do(req.WithContext(r.Context()))
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/authz/remote.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func (a *AuthorizerRemote) Authorize(r *http.Request, session *authn.Authenticat
req.Header.Set(hdr, headerValue.String())
}

res, err := a.client.Do(req)
res, err := a.client.Do(req.WithContext(r.Context()))
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/authz/remote_json.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (a *AuthorizerRemoteJSON) Authorize(r *http.Request, session *authn.Authent
req.Header.Add("Authorization", authz)
}

res, err := a.client.Do(req)
res, err := a.client.Do(req.WithContext(r.Context()))
if err != nil {
return errors.WithStack(err)
}
Expand Down
2 changes: 1 addition & 1 deletion pipeline/mutate/mutator_hydrator.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ func (a *MutatorHydrator) Mutate(r *http.Request, session *authn.AuthenticationS
client.Transport = httpx.NewResilientRoundTripper(a.client.Transport, maxRetryDelay, giveUpAfter)
}

res, err := client.Do(req)
res, err := client.Do(req.WithContext(r.Context()))
if err != nil {
return errors.WithStack(err)
}
Expand Down

0 comments on commit b7fa48f

Please sign in to comment.