-
-
Notifications
You must be signed in to change notification settings - Fork 162
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support using an existing reqwest::Client when making requests #253
Comments
Thanks for filing this issue! I agree this should be fixed, and now is a good time since I've already started merging breaking changes for the next major release. I'm planning to change the request/response API to use traits as described here, and we can simply make the reqwest implementation of those traits stateful to allow client reuse. |
That sounds ideal! I look forward to that landing. For now we'll have to deal with the copy-paste but I'll link back to this issue so we can migrate when possible. |
This is now released in 5.0.0-alpha.1. If you can, please try it out and let me know if you find any issues that should be fixed before stabilizing the 5.0 API. There's an Upgrade Guide to help. |
The
oauth2::reqwest::async_http_client
function creates a newreqwest::Client
on every invocation. This completely precludes the possibility of using HTTP Keep-Alive or DNS caching as supported byreqwest::Client
, so every single request is going to make a DNS query, create a new TCP connection, and perform an SSL handshake. This is horribly inefficient and can cause problems in applications making a large number of requests.We can take the existing function and copy-paste it to support using an existing client, but this doesn't seem very DRY.
I would suggest splitting this function into two: one that creates a new client and one that uses an existing one (the former can delegate to the latter). For example (this code is untested):
Now if we want to use our own client, we can do
.request_async(|request| async_http_client_with_client(&client, request))
.The text was updated successfully, but these errors were encountered: