Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions src/client/Microsoft.Identity.Client/Http/HttpManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,12 +223,6 @@ private static HttpRequestMessage CreateRequestMessage(Uri endpoint, IDictionary

requestMessage.Headers.Accept.Clear();

#if NET5_0_OR_GREATER
// On .NET 5.0 and later, HTTP2 is supported through the SDK and Entra is HTTP2 compatible
// Note that HttpClient.DefaultRequestVersion does not work when using HttpRequestMessage objects
requestMessage.Version = HttpVersion.Version20; // Default to HTTP/2
requestMessage.VersionPolicy = HttpVersionPolicy.RequestVersionOrLower; // Allow fallback to HTTP/1.1
#endif
if (headers != null)
{
foreach (KeyValuePair<string, string> kvp in headers)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,6 @@ public HttpSnifferClientFactory()
LastHttpContentData = req.Content.ReadAsStringAsync().GetAwaiter().GetResult();
}

// check the .net runtime
var framework = RuntimeInformation.FrameworkDescription;

// This will match ".NET 5.0", ".NET 6.0", ".NET 7.0", ".NET 8.0", etc.
if (framework.StartsWith(".NET ", StringComparison.OrdinalIgnoreCase))
{
// Extract the version number
var versionString = framework.Substring(5).Trim(); // e.g., "6.0.0"
if (Version.TryParse(versionString, out var version) && version.Major >= 5)
{
Assert.AreEqual(new Version(2, 0), req.Version, $"Request version mismatch: {req.Version}. MSAL on NET 5+ expects HTTP/2.0 for all requests.");
// ESTS-R endpoint does not support HTTP/2.0, so we don't assert this
}
}

RequestsAndResponses.Add((req, res));

Trace.WriteLine($"[MSAL][HTTP Request]: {req}");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -634,38 +634,5 @@ protected override Task<HttpResponseMessage> SendAsync(HttpRequestMessage reques
return Task.FromResult(new HttpResponseMessage(System.Net.HttpStatusCode.OK));
}
}

#if NET
[TestMethod]
public async Task SendRequestAsync_SetsHttp2VersionAndPolicy()
{
// Arrange
var handler = new CapturingHandler();
var httpClient = new HttpClient(handler);
var httpClientFactory = Substitute.For<IMsalHttpClientFactory>();
httpClientFactory.GetHttpClient().Returns(httpClient);

var httpManager = new Client.Http.HttpManager(httpClientFactory, disableInternalRetries: true);

// Act
await httpManager.SendRequestAsync(
new Uri("https://login.microsoftonline.com/common/discovery/instance?api-version=1.1&authorization_endpoint=https://login.microsoftonline.com/common/oauth2/v2.0/authorize"),
null,
null,
HttpMethod.Get,
Substitute.For<ILoggerAdapter>(),
doNotThrow: true,
bindingCertificate: null,
validateServerCert: null,
cancellationToken: CancellationToken.None,
retryPolicy: Substitute.For<IRetryPolicy>()
).ConfigureAwait(false);

// Assert
Assert.IsNotNull(handler.CapturedRequest);
Assert.AreEqual(HttpVersion.Version20, handler.CapturedRequest.Version);
Assert.AreEqual(HttpVersionPolicy.RequestVersionOrLower, handler.CapturedRequest.VersionPolicy);
}
#endif
}
}