diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fee787..c552716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,11 +7,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [1.4.2] - 2024-05-21 + ### Added - Added an optional parameter to kiota middleware factory so options can be configured directly. [#233](https://github.com/microsoft/kiota-http-dotnet/issues/233) - `GetDefaultHandlerTypes` added to `KiotaClientFactory` if you're creating your own `HttpClient` and still want to use the default handlers. +### Changed + +- Fixed an issue where fixed versions of abstractions would result in restore failures. [#256](https://github.com/microsoft/kiota-http-dotnet/issues/256) + ## [1.4.1] - 2024-05-07 ## Changed @@ -26,20 +32,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [1.3.12] - 2024-04-22 -- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage (https://github.com/microsoft/kiota-http-dotnet/issues/242) -- Adds `ConfigureAwait(false)` calls to async calls (https://github.com/microsoft/kiota-http-dotnet/issues/240). +- UriReplacementHandler improvements to be added to middleware pipeline by default and respects options set in the HttpRequestMessage [#242](https://github.com/microsoft/kiota-http-dotnet/issues/242) +- Adds `ConfigureAwait(false)` calls to async calls [#240](https://github.com/microsoft/kiota-http-dotnet/issues/240). ## [1.3.11] - 2024-04-19 ## Changed -- Fixes default handler for NET framework to unlock HTTP/2 scenarios (https://github.com/microsoft/kiota-http-dotnet/issues/237) +- Fixes default handler for NET framework to unlock HTTP/2 scenarios [#237](https://github.com/microsoft/kiota-http-dotnet/issues/237) ## [1.3.10] - 2024-04-19 ## Changed -- Have made System.* dependencies only be included on Net Standard's TFM & net 5 (https://github.com/microsoft/kiota-http-dotnet/issues/230) +- Have made System.* dependencies only be included on Net Standard's TFM & net 5 [#230](https://github.com/microsoft/kiota-http-dotnet/issues/230) ## [1.3.9] - 2024-04-17 @@ -92,7 +98,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ### Added -- Fixes multiple initialization of `ActivitySource` instances on each request send(https://github.com/microsoft/kiota-http-dotnet/issues/161). +- Fixes multiple initialization of `ActivitySource` instances on each request send [#161](https://github.com/microsoft/kiota-http-dotnet/issues/161). ## [1.3.0] - 2023-11-02 diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs index cd15006..1c8ae11 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs @@ -364,9 +364,9 @@ public async Task SendReturnsObjectOnContent(HttpStatusCode statusCode) var mockParseNode = new Mock(); mockParseNode.Setup(x => x.GetObjectValue(It.IsAny>())) .Returns(new MockEntity()); - var mockParseNodeFactory = new Mock(); - mockParseNodeFactory.Setup(x => x.GetRootParseNode(It.IsAny(), It.IsAny())) - .Returns(mockParseNode.Object); + var mockParseNodeFactory = new Mock(); + mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(mockParseNode.Object)); var adapter = new HttpClientRequestAdapter(_authenticationProvider, httpClient: client, parseNodeFactory: mockParseNodeFactory.Object); var requestInfo = new RequestInformation { @@ -393,7 +393,7 @@ public async Task RetriesOnCAEResponse() StatusCode = methodCalled ? HttpStatusCode.OK : HttpStatusCode.Unauthorized, Content = new StreamContent(new MemoryStream(Encoding.UTF8.GetBytes("Test"))) }; - if (!methodCalled) + if(!methodCalled) response.Headers.WwwAuthenticate.Add(new("Bearer", "realm=\"\", authorization_uri=\"https://login.microsoftonline.com/common/oauth2/authorize\", client_id=\"00000003-0000-0000-c000-000000000000\", error=\"insufficient_claims\", claims=\"eyJhY2Nlc3NfdG9rZW4iOnsibmJmIjp7ImVzc2VudGlhbCI6dHJ1ZSwgInZhbHVlIjoiMTY1MjgxMzUwOCJ9fX0=\"")); methodCalled = true; return Task.FromResult(response); @@ -440,7 +440,7 @@ public async Task SetsTheApiExceptionStatusCode(HttpStatusCode statusCode) var response = await adapter.SendPrimitiveAsync(requestInfo); Assert.Fail("Expected an ApiException to be thrown"); } - catch (ApiException e) + catch(ApiException e) { Assert.Equal((int)statusCode, e.ResponseStatusCode); Assert.True(e.ResponseHeaders.ContainsKey("request-id")); @@ -467,9 +467,9 @@ public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC var mockParseNode = new Mock(); mockParseNode.Setup(x => x.GetObjectValue(It.IsAny>())) .Returns(new MockError("A general error occured")); - var mockParseNodeFactory = new Mock(); - mockParseNodeFactory.Setup(x => x.GetRootParseNode(It.IsAny(), It.IsAny())) - .Returns(mockParseNode.Object); + var mockParseNodeFactory = new Mock(); + mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(mockParseNode.Object)); var adapter = new HttpClientRequestAdapter(_authenticationProvider, mockParseNodeFactory.Object, httpClient: client); var requestInfo = new RequestInformation { @@ -485,7 +485,7 @@ public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC var response = await adapter.SendPrimitiveAsync(requestInfo, errorMapping); Assert.Fail("Expected an ApiException to be thrown"); } - catch (MockError mockError) + catch(MockError mockError) { Assert.Equal((int)statusCode, mockError.ResponseStatusCode); Assert.Equal("A general error occured", mockError.Message); @@ -511,9 +511,9 @@ public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode) var mockParseNode = new Mock(); mockParseNode.Setup(x => x.GetObjectValue(It.IsAny>())) .Returns(new MockError("A general error occured: " + statusCode.ToString())); - var mockParseNodeFactory = new Mock(); - mockParseNodeFactory.Setup(x => x.GetRootParseNode(It.IsAny(), It.IsAny())) - .Returns(mockParseNode.Object); + var mockParseNodeFactory = new Mock(); + mockParseNodeFactory.Setup(x => x.GetRootParseNodeAsync(It.IsAny(), It.IsAny(), It.IsAny())) + .Returns(Task.FromResult(mockParseNode.Object)); var adapter = new HttpClientRequestAdapter(_authenticationProvider, mockParseNodeFactory.Object, httpClient: client); var requestInfo = new RequestInformation { @@ -529,7 +529,7 @@ public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode) var response = await adapter.SendPrimitiveAsync(requestInfo, errorMapping); Assert.Fail("Expected an ApiException to be thrown"); } - catch (ApiException apiException) + catch(ApiException apiException) { Assert.Equal((int)statusCode, apiException.ResponseStatusCode); Assert.Contains("The server returned an unexpected status code and no error factory is registered for this code", apiException.Message); diff --git a/src/HttpClientRequestAdapter.cs b/src/HttpClientRequestAdapter.cs index bf30bf3..51bc17c 100644 --- a/src/HttpClientRequestAdapter.cs +++ b/src/HttpClientRequestAdapter.cs @@ -441,8 +441,11 @@ private async Task ThrowIfFailedResponse(HttpResponseMessage response, Dictionar using var contentStream = await (response.Content?.ReadAsStreamAsync() ?? Task.FromResult(Stream.Null)).ConfigureAwait(false); #endif if(contentStream == Stream.Null || (contentStream.CanSeek && contentStream.Length == 0)) - return null;// ensure a usefule stream is passed to the factory - var rootNode = pNodeFactory.GetRootParseNode(responseContentType!, contentStream); + return null;// ensure a useful stream is passed to the factory +#pragma warning disable CS0618 // Type or member is obsolete + //TODO remove with v2 + var rootNode = pNodeFactory is IAsyncParseNodeFactory asyncParseNodeFactory ? await asyncParseNodeFactory.GetRootParseNodeAsync(responseContentType!, contentStream, cancellationToken).ConfigureAwait(false) : pNodeFactory.GetRootParseNode(responseContentType!, contentStream); +#pragma warning restore CS0618 // Type or member is obsolete return rootNode; } private const string ClaimsKey = "claims"; @@ -538,7 +541,7 @@ private HttpRequestMessage GetRequestMessageFromRequestInformation(RequestInform { Method = new HttpMethod(requestInfo.HttpMethod.ToString().ToUpperInvariant()), RequestUri = requestUri, - Version=new Version(2,0) + Version = new Version(2, 0) }; if(requestInfo.RequestOptions.Any()) diff --git a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj index 8f30e5b..f03b2c8 100644 --- a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj +++ b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj @@ -35,20 +35,23 @@ true $(NoWarn);NU5048;NETSDK1138 - + true - + true - + - + @@ -56,7 +59,8 @@ - + @@ -69,4 +73,4 @@ - + \ No newline at end of file