algoliasearch-client-csharp
algoliasearch-client-csharp copied to clipboard
Appending to AlgoliaConfig.DefaultHeaders instead of overriding
- Algolia Client Version: 6.7.0
- Language Version: .NET 3.1
Description
Few snippets from our documentation are overriding the AlgoliaConfig.DefaultHeaders
instead of appending values to them. While the issue seems legit, I'm not sure if we should simply change the snippets, or fix the API client code so that user-defined DefaultHeaders
are used but appended to the original default headers, instead of overriding them.
Steps To Reproduce
-
in the doc: List the snippets setting the
DefaultHeaders
in our documentation (usinggrep -lr 'DefaultHeaders = new Dictionary' *
) - in the client: https://github.com/algolia/algoliasearch-client-csharp/blob/6.7.0/src/Algolia.Search/Clients/AlgoliaConfig.cs#L51-L58
Original user report on HelpScout
Just a heads up, the .NET example here will override the App ID and API key. So your requests will fail using the example with a 403. Here's a better example:
var configuration = new SearchConfig("AppID", "••••••••••••••••••••"); configuration.DefaultHeaders.Add("NAME-OF-HEADER", "value-of-header");
The code above will simply add the new header, keeping the Algolia Defaults created when you instantiate a new SearchConfig instance.
URL: https://www.algolia.com/doc/api-reference/api-methods/set-extra-header/#examples
Hi. I reported the issue and am willing to help out to get this resolved.
One quick fix might be to simply mark the DefaultHeaders
property private set
or get
only. Although the collection would be mutable, the user would have to make a conscious effort to clear
all of the headers or override the default headers like AlgoliaApplicationHeader
and AlgoliaApiKeyHeader
.
Another solution would be to mark DefaultHeaders
as a read only collection and create a new property AdditionalHeaders
. But then we'd have to make sure that these are merged everywhere DefaultHeaders
is used.
Again just some suggestions. Let me know if you need any other help from me or if you'd like me to submit a pull request.
Closing this as the new client we just released (7.0) splits the defaults and user headers.