twisted / treq

Python requests like API built on top of Twisted's HTTP client.
Other
587 stars 139 forks source link

Requests Like Client Certification #285

Open yesennes opened 4 years ago

yesennes commented 4 years ago

In requests, you can specify the client cert with an optional parameter like: requests.get(url, cert=[client_cert_location, client_cert_key_location]). I would be nice to be able to specify the client cert in the same way.

twm commented 4 years ago

Unfortunately I think that the specific API exposed by requests (the cert argument) is in conflict with another Treq feature: the ability to pass a custom Agent. Control over TLS options is a parameter to the agent, but since Treq doesn't necessarily instantiate the agent we can't necessarily pass it.

The capability is available, though: when instantiating the Agent pass the agent a custom IPolicyForHTTPS that uses optionsForClientTLS to specify a client certificate.

I do think that Treq could make this cleaner. Perhaps expose an API for composing agents like Treq does internally inside HTTPClient, and extend that to support client certificates?