Cosmonaut
Cosmonaut copied to clipboard
Proxy Support
Can support be added for proxy authentication? Version 2.2.1 of Azure.DocumentDB allows for specifying an HttpClientHandler
in the DocumentClient
constructor , through which proxy settings can be set so that anyone behind a proxy can connect to Azure Cosmos DB?
I'm using it like this in my own implementation:
var documentClient = new DocumentClient(serviceEndpoint, authKey, handler: handler);
Hey @goda,
Cosmonaut allows you to provide your own IDocumentClient
through the ICosmonautClient
which is required in one of the constructors for the CosmosStore
so a temporary workaround would be to register that in your IoC.
I am definitely interested in add this in a more user friendly way. Do you have any proposals on how you can see this working with Cosmonaut?
Thanks, Nick
Thanks Nick! The workaround was simple to implement and works very well. Great work on the library - I'm planning on spending some time to integrate it into my project which uses repository pattern to access Cosmos.
In terms of a suggestion to make the proxy option easier to implement, to me it seems like it is doable via some minor changes.
Adding a property of type HttpClientHandler
(e.g. ClientHandler
) to CosmosStoreSettings
would allow one to simply pass the proxy configured HttpClientHandler
when initializing the CosmosStoreSettings
. Finally a simple change to the DocumentClientFactory
method is required:
internal static IDocumentClient CreateDocumentClient(CosmosStoreSettings settings)
{
return new DocumentClient(settings.EndpointUrl, settings.AuthKey, settings.ClientHandler ?? new HttpClientHandler(), settings.ConnectionPolicy ?? ConnectionPolicy.Default, settings.ConsistencyLevel);
}
The only caveat with this is that due to the limited DocumentClient
constructor overloads - currently it is not possible to both have HttpClientHandler
and JsonSerializerSettings
passed. I'm sure there are other ways of working around this issue but I haven't explored since I don't need the JsonSerializerSettings
option.
Hey @goda I had a look into this and it looks like, unless I use reflection, there is no way to have both an HttpClientHandler
and JsonSerializerSettings
like you mentioned. I don't really wanna use reflection on this one, so I'll try to raise it with the CosmosDB team.