diff --git a/CHANGELOG.md b/CHANGELOG.md index ebc761282..fd01a1ef5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,6 +23,7 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/). - Added `-KeyColumn` to `Add-PnPDataRowsToSiteTemplate` which allows for overwriting existing list items in a site template [#2616](https://github.com/pnp/powershell/pull/2616) - Added `Get-PnPFolderStorageMetric` which allows storage usage of a specific folder to be retrieved [#2646](https://github.com/pnp/powershell/pull/2646) - Added `IsTeamsConnected`, `IsTeamsChannelConnected` and `TeamChannelType` to be returned when `Get-PnPTenantSite` cmdlet is executed. [#2656](https://github.com/pnp/powershell/pull/2656) +- Added `HTTP/2` support for all HTTP requests to improve performance for HTTP requests. [#2687](https://github.com/pnp/powershell/pull/2687) - Added `-EnvironmentVariable` parameter to `Connect-PnPOnline` to connect using Azure environment variables. [#2681](https://github.com/pnp/powershell/pull/2681) - Added `ResponseHeadersVariable` parameter to the `Invoke-PnPSPRestMethod` which if specified will store the response headers values in the PowerShell variable name that is specified. [#2711](https://github.com/pnp/powershell/pull/2711) - Added `-Filter` parameter to `Get-PnPAzureADServicePrincipal` cmdlet to retrieve specific application registrations based on filter conditions. It supports simple and advanced queries. [#2710](https://github.com/pnp/powershell/pull/2710) diff --git a/src/Commands/AzureAD/RegisterManagementShellAccess.cs b/src/Commands/AzureAD/RegisterManagementShellAccess.cs index 621d3114b..2886fe43f 100644 --- a/src/Commands/AzureAD/RegisterManagementShellAccess.cs +++ b/src/Commands/AzureAD/RegisterManagementShellAccess.cs @@ -102,6 +102,7 @@ protected override void ProcessRecord() var httpClient = Framework.Http.PnPHttpClient.Instance.GetHttpClient(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, $"https://{GetGraphEndPoint()}/v1.0/organization")) { + requestMessage.Version = new System.Version(2, 0); requestMessage.Headers.Add("Authorization", $"Bearer {accessToken}"); requestMessage.Headers.Accept.Add(new System.Net.Http.Headers.MediaTypeWithQualityHeaderValue("application/json")); var response = httpClient.SendAsync(requestMessage).GetAwaiter().GetResult(); diff --git a/src/Commands/Base/InvokeSPRestMethod.cs b/src/Commands/Base/InvokeSPRestMethod.cs index e72889b6e..5ecafabd1 100644 --- a/src/Commands/Base/InvokeSPRestMethod.cs +++ b/src/Commands/Base/InvokeSPRestMethod.cs @@ -81,6 +81,7 @@ protected override void ExecuteCmdlet() { request.Headers.Add("IF-MATCH", "*"); } + request.Version = new Version(2, 0); PnPHttpClient.AuthenticateRequestAsync(request, ClientContext).GetAwaiter().GetResult(); diff --git a/src/Commands/Base/TokenHandling.cs b/src/Commands/Base/TokenHandling.cs index 2ebe31cb1..4eacc40d7 100644 --- a/src/Commands/Base/TokenHandling.cs +++ b/src/Commands/Base/TokenHandling.cs @@ -148,6 +148,7 @@ internal static async Task GetManagedIdentityTokenAsync(Cmdlet cmdlet, H using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, tokenRequestUrl)) { + requestMessage.Version = new Version(2, 0); requestMessage.Headers.Add("Metadata", "true"); if (!string.IsNullOrEmpty(identityHeader)) { diff --git a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs index 0148a3f93..393342dad 100644 --- a/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs +++ b/src/Commands/PowerPlatform/PowerAutomate/ExportFlow.cs @@ -2,6 +2,7 @@ using PnP.PowerShell.Commands.Base; using PnP.PowerShell.Commands.Base.PipeBinds; using PnP.PowerShell.Commands.Utilities.REST; +using System; using System.Management.Automation; using System.Net.Http; using System.Text.Json; @@ -122,6 +123,7 @@ protected override void ExecuteCmdlet() var packageLink = valueElement.GetString(); using (var requestMessage = new HttpRequestMessage(HttpMethod.Get, packageLink)) { + requestMessage.Version = new Version(2, 0); //requestMessage.Headers.Add("Authorization", $"Bearer {AccessToken}"); var response = Connection.HttpClient.SendAsync(requestMessage).GetAwaiter().GetResult(); var byteArray = response.Content.ReadAsByteArrayAsync().GetAwaiter().GetResult(); diff --git a/src/Commands/Utilities/BrowserHelper.cs b/src/Commands/Utilities/BrowserHelper.cs index 816af621f..968789770 100644 --- a/src/Commands/Utilities/BrowserHelper.cs +++ b/src/Commands/Utilities/BrowserHelper.cs @@ -277,6 +277,7 @@ internal static bool GetWebBrowserPopup(string siteUrl, string title, (string ur string requestUrl = string.Format("{0}/_api/contextinfo", siteUrl.TrimEnd('/')); HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Post, requestUrl); + request.Version = new Version(2, 0); request.Headers.Add("accept", "application/json;odata=nometadata"); HttpResponseMessage response = await httpClient.SendAsync(request); diff --git a/src/Commands/Utilities/REST/GraphHelper.cs b/src/Commands/Utilities/REST/GraphHelper.cs index 36789c25e..26a612b0c 100644 --- a/src/Commands/Utilities/REST/GraphHelper.cs +++ b/src/Commands/Utilities/REST/GraphHelper.cs @@ -55,6 +55,7 @@ private static HttpRequestMessage GetMessage(string url, HttpMethod method, PnPC } var message = new HttpRequestMessage(); + message.Version = new Version(2, 0); message.Method = method; message.Headers.TryAddWithoutValidation("Accept", "application/json"); message.RequestUri = !url.StartsWith("https://", StringComparison.OrdinalIgnoreCase) ? new Uri($"https://{connection.GraphEndPoint}/{url}") : new Uri(url); diff --git a/src/Commands/Utilities/REST/RestHelper.cs b/src/Commands/Utilities/REST/RestHelper.cs index bfe71a9fe..6bc0991ea 100644 --- a/src/Commands/Utilities/REST/RestHelper.cs +++ b/src/Commands/Utilities/REST/RestHelper.cs @@ -381,7 +381,7 @@ public static async Task PatchAsync(HttpClient httpClient, string url, str public static async Task PatchAsync(HttpClient httpClient, string url, string accessToken, object payload, string accept = "application/json") { - HttpRequestMessage message = null; + HttpRequestMessage message = null; if (payload != null) { #if NETFRAMEWORK @@ -642,6 +642,7 @@ private static HttpRequestMessage GetMessage(string url, HttpMethod method, stri } var message = new HttpRequestMessage(); + message.Version = new Version(2, 0); message.Method = method; message.RequestUri = new Uri(url); if (!string.IsNullOrEmpty(accessToken)) @@ -665,6 +666,7 @@ private static HttpRequestMessage GetMessage(string url, HttpMethod method, Clie } var message = new HttpRequestMessage(); + message.Version = new Version(2, 0); message.Method = method; message.RequestUri = new Uri(url); message.Headers.Accept.Add(MediaTypeWithQualityHeaderValue.Parse(accept)); diff --git a/src/Commands/Utilities/VersionChecker.cs b/src/Commands/Utilities/VersionChecker.cs index ef9dd94e3..185773068 100644 --- a/src/Commands/Utilities/VersionChecker.cs +++ b/src/Commands/Utilities/VersionChecker.cs @@ -132,8 +132,9 @@ internal static string GetAvailableVersion(bool isNightly) // Deliberately lowering timeout as the version check is not critical so in case of a slower or blocked internet connection, this should not block the cmdlet for too long httpClient.Timeout = TimeSpan.FromSeconds(VersionCheckTimeOut); - - var response = httpClient.SendAsync(new HttpRequestMessage(HttpMethod.Get, isNightly ? NightlyVersionCheckUrl : ReleaseVersionCheckUrl)).GetAwaiter().GetResult(); + var request = new HttpRequestMessage(HttpMethod.Get, isNightly ? NightlyVersionCheckUrl : ReleaseVersionCheckUrl); + request.Version = new Version(2, 0); + var response = httpClient.SendAsync(request).GetAwaiter().GetResult(); if (response.IsSuccessStatusCode) { var onlineVersion = response.Content.ReadAsStringAsync().GetAwaiter().GetResult();