From d4fbd26b3c1012daa7c9f242a4249ed0948caa8b Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 14:52:41 -0400 Subject: [PATCH 1/4] bugfix: version range for abstractions Signed-off-by: Vincent Biret --- CHANGELOG.md | 16 +++++++++++----- ...Microsoft.Kiota.Http.HttpClientLibrary.csproj | 16 ++++++++++------ 2 files changed, 21 insertions(+), 11 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4fee787..0d7264f 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 () +- Adds `ConfigureAwait(false)` calls to async calls (). ## [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 () ## [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 () ## [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(). ## [1.3.0] - 2023-11-02 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 From cffe43c0de7e7f65560b8930e0e3f3e75f726668 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 14:56:49 -0400 Subject: [PATCH 2/4] chore: fixes changelog formatting Signed-off-by: Vincent Biret --- CHANGELOG.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0d7264f..c552716 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,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 () -- Adds `ConfigureAwait(false)` calls to async calls (). +- 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 () +- 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 () +- 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 @@ -98,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(). +- 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 From e698ffeeeba772fe692d64eb013030d269f10cef Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 15:07:43 -0400 Subject: [PATCH 3/4] chore: updates references to factories following abstractions update --- .../RequestAdapterTests.cs | 26 +++++++++---------- src/HttpClientRequestAdapter.cs | 9 ++++--- 2 files changed, 19 insertions(+), 16 deletions(-) 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..7626fc8 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) : 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()) From 58127f960ff267abea5fba2fbaa2d1aa0bc02521 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 21 May 2024 15:09:56 -0400 Subject: [PATCH 4/4] chore: adds missing configure await Signed-off-by: Vincent Biret --- src/HttpClientRequestAdapter.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/HttpClientRequestAdapter.cs b/src/HttpClientRequestAdapter.cs index 7626fc8..51bc17c 100644 --- a/src/HttpClientRequestAdapter.cs +++ b/src/HttpClientRequestAdapter.cs @@ -444,7 +444,7 @@ private async Task ThrowIfFailedResponse(HttpResponseMessage response, Dictionar 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) : pNodeFactory.GetRootParseNode(responseContentType!, contentStream); + 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; }