Skip to content
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

Added implementation of SPWebRequestExecutor that utilizes HttpClient #261

Merged
merged 2 commits into from
Apr 14, 2021

Conversation

patrikhellgren
Copy link
Contributor

Q A
Bug fix? no
New feature? yes
New sample? no
Related issues?

What's in this Pull Request?

Added an implementation of WebRequestExecutorFactory and SPWebRequestExecutor that utilizes HttpClient instead of HttpWebRequest.
This has the following benefits over the default implementation:

  • It makes it easier to prevent port exhaustion in for example larger scale provisioning scenarios
  • It is faster
  • You can take advantage of all the other benefits that comes with HttpClient

Usage example:

var authManager = new PnP.Framework.AuthenticationManager(clientId, certificate, tenantId);
var clientContext = authManager.GetContext(siteUrl);
clientContext.WebRequestExecutorFactory = new HttpClientWebRequestExecutorFactory(PnPHttpClient.Instance.GetHttpClient());
clientContext.Load(clientContext.Web, w => w.Title);
await clientContext.ExecuteQueryRetryAsync();

@jansenbe
Copy link
Contributor

Nice work @patrikhellgren! Are you using this for all your CSOM contexts? Wondering if we should make this implementation the default one...

@jansenbe jansenbe self-assigned this Apr 14, 2021
jansenbe added a commit that referenced this pull request Apr 14, 2021
@jansenbe jansenbe merged commit 1febaaa into pnp:dev Apr 14, 2021
@patrikhellgren
Copy link
Contributor Author

@jansenbe I only made this implementation a couple of weeks ago but have been using it since then and my intention is to use it for all CSOM work hereafter since it seems to be running really well. I have tested it in our provisioning solution that runs in Azure Functions with some really large templates so I feel that I can say that at least the provisioning scenarios has been tested.
If we were to make this the default implementation I still think that HttpClientWebRequestExecutorFactory should be public so that any HttpClient could be used if you had some special requirements, even though PnPHttpClient should be the default one.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants