[CatalogClient] extra headers in Catalog request#21324
Conversation
Allow the setting of custom extra headers in CatalogRequestOptions. Use-case: Passing in information from the front-end or another backend service for example for logging request information (like identity, correlation-id, etc.). Signed-off-by: Rickard Dybeck <dybeck@spotify.com>
Changed Packages
|
Signed-off-by: Rickard Dybeck <dybeck@spotify.com>
Uffizzi Ephemeral Environment - Virtual ClusterYour cluster
Access the |
|
Uffizzi Cluster |
Signed-off-by: Rickard Dybeck <dybeck@spotify.com>
Rugvip
left a comment
There was a problem hiding this comment.
I believe you can already do this by decorating the fetch API before passing it to the catalog client. You should be able to use createFetchApi to help out with the wrapping of the existing fetch as well:
|
@Rugvip I spent some time to look into that, and I'm not at all sure how to do it modifying the fetchApi with a middleware without making the code really complicated instead of just passing it on the call that already has support for (very limited) options |
|
Hm the examples are identity and correlation-ID - at least the second of those is a per-request thing right? Identity in the form of specifically the Backstage token should be injected automatically by the fetchApi as long as it's been passed to the client in the first place - which it is by default. |
|
Realized there's no need for using createApiFactory({
api: catalogApiRef,
deps: {
discoveryApi: discoveryApiRef,
fetchApi: fetchApiRef,
},
factory: ({ discoveryApi, fetchApi: { fetch: innerFetch } }) =>
new CatalogClient({
discoveryApi,
fetchApi: {
fetch: async (input, init) => {
const request = new Request(input as any, init);
request.headers.set('correlation-id', '4');
return innerFetch(request);
},
},
}),
}), |
|
@Rugvip The problem that I'm trying to solve is setting it to a different thing in each call to forward headers from an incoming call for example |
|
I noted this down in #15999 so that we can at very least try to tackle this as part of broader service auth/protected by default work. Also noted that the particular problem of forwarding information from an incoming request to outgoing ones is something that could potentially be solved by context/thread local storage, which is something we might explore again as part of that work. |
Allow the setting of custom extra headers in CatalogRequestOptions.
Use-case: Passing in information from the front-end or another backend service for example for logging request information (like identity, correlation-id, etc.).
Hey, I just made a Pull Request!
✔️ Checklist
Signed-off-byline in the message. (more info)