Skip to content

Hook for Propagating Context/Headers #57

Answered by earthboundkid
jkratz55 asked this question in Ideas
Discussion options

You must be logged in to vote

In terms of the warning from the standard library, that's why you need to clone a request before modifying it in a transport. See the UserAgentTransport for example, which adds a header to the cloned request.

Another option which you haven't listed is creating a request.Config like

func CtxConfig(ctx context.Context) request.Config {
  return func(rb *Builder) {
	requestId := ctx.Value(ContextXRequestID).(string)
	realIP := ctx.Value(ContextXRealIP).(string)
	forwardFor := ctx.Value(ContextXForwardFor).(string)
	uid := ctx.Value(ContextUID).(string)

	rb.Header("X-Request-ID", requestId)
	rb.Header("X-Real-IP", realIP)
	rb.Header("X-Forwarded-For", forwardFor)
	rb.Header("X-App-User-ID", uid

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@earthboundkid
Comment options

Answer selected by jkratz55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Ideas
Labels
None yet
2 participants