Router Response Header Setting
The router allows you to set custom response headers that are applied to the final HTTP response sent to the client. These headers are set at the router level, meaning they are applied after all subgraph requests have been completed and their responses have been aggregated. This is different from subgraph response headers, which are processed for each individual subgraph request—router response header operations run exactly once per request, after all subgraph responses have been returned and processed, but before the final response is sent to the client.Configuration Example
You can configure router response headers in your router configuration file using expressions:How it works
After all subgraph requests are completed and their responses aggregated, the router evaluates the expression. In this example:- The router checks if the incoming request contains a header
X-Get-Statuswith the value"demo" - If true, it sets the response header
X-Demo-Headerto"demo-value" - If false, the expression returns an empty string, and the header is not set (the router will not set headers with empty string values)
Currently, it is not possible to access headers propagated from subgraphs within router-level expressions, or programmatically unset any headers that were propagated at the subgraph level. Router-level expressions can only access request context (like incoming request headers), not the outgoing response headers set by subgraphs.