Inject response headers for all requests

Hi All,

Have been playing with Tyk Community Edition Gateway for quite some time. I’d quickly get to my query.

Q: I’d like to inject a correlation id to all requests (to proxy/upstream) and to responses (back to originating client) to track request-responses end to end.

What I’ve done so far:

  1. Set global headers for the proxy/upstream:
"global_headers": {
  "X-Request-Id": "$tyk_context.request_id"
}
  1. Set transform_response_headers
"transform_response_headers": [
{
  "add_headers": {"X-Request-Id": "$tyk_context.request_id"},
  "path": "(.*)",
  "method": "POST"
}

This perfectly works, but I’ve some queries:

  1. Is there an easier way to do this?
  2. Are the global_headers only to the upstream and applied only on request? Won’t it work on responses?
  3. Can the transform_response_headers support any HTTP method without explicitly mentioning it? Else, do I have to add more array items for GET, PUT, DELETE etc.?

Thank you for all the support in advance.

Regards,
Sreekanth

1 Like