You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
We’re using JWT authentication, but also need to include an ES-Client-Authentication header with a pre-shared secret for each request. We don’t want to set this value using GlobalHeaders, since that would require recreating the Elastic client whenever the secret rotates. Instead, we’d like to add the header dynamically to every request.
OnRequestDataCreated seems like a good fit for this. Is there a simpler or more standard way to achieve dynamic per-request headers, without having to implement and maintain a custom IRequestInvoker or HttpMessageHandler?
Hi @mathiasaap , would it work for you to set this header as part of the request?
awaitclient.SearchAsync<Person>(x =>x.Query(...).RequestConfiguration(x =>x.GlobalHeaders(/* these headers are actually local / per-request, and not global */)));
Instead of a descriptor, new RequestConfiguration(...) could be used to create a new global instance as soon as the secret rotates. This instance can be passed to .RequestConfiguration() instead of using the fluent syntax.
I will check if we can re-introduce something like the OnRequestDataCreated callback, when I have some time. The architecture changed quite a bit in the meantime.
Thanks for the suggestion. While this approach works technically, it introduces awkwardness by mixing setup and usage concerns. We’ll implement a workaround for now, but having something like an OnRequestDataCreated hook would greatly improve the ability to centralize configuration.
Elastic.Clients.Elasticsearch version: 8.18.0
Elasticsearch version: 8.18.1
.NET runtime version: 8
Description of the problem including expected versus actual behavior:
The property OnRequestDataCreated is missing from the class ElasticsearchClientSettings, but should be available according to the documentation: https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/_options_on_elasticsearchclientsettings
Steps to reproduce:
This following code should compile, but does not because OnRequestDataCreated does not exist
The text was updated successfully, but these errors were encountered: