From e5d8cdab985b454e828217d479812293a930ef16 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 24 Apr 2024 21:51:18 +0000 Subject: [PATCH 01/17] Bump dependabot/fetch-metadata from 2.0.0 to 2.1.0 Bumps [dependabot/fetch-metadata](https://github.com/dependabot/fetch-metadata) from 2.0.0 to 2.1.0. - [Release notes](https://github.com/dependabot/fetch-metadata/releases) - [Commits](https://github.com/dependabot/fetch-metadata/compare/v2.0.0...v2.1.0) --- updated-dependencies: - dependency-name: dependabot/fetch-metadata dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/auto-merge-dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/auto-merge-dependabot.yml b/.github/workflows/auto-merge-dependabot.yml index 145487d..72d96dd 100644 --- a/.github/workflows/auto-merge-dependabot.yml +++ b/.github/workflows/auto-merge-dependabot.yml @@ -19,7 +19,7 @@ jobs: steps: - name: Dependabot metadata id: metadata - uses: dependabot/fetch-metadata@v2.0.0 + uses: dependabot/fetch-metadata@v2.1.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" From a48472147fab1f8ab32594eef526d4ad65ae32e9 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 29 Apr 2024 21:23:27 +0000 Subject: [PATCH 02/17] Bump xunit.runner.visualstudio from 2.5.8 to 2.8.0 Bumps [xunit.runner.visualstudio](https://github.com/xunit/visualstudio.xunit) from 2.5.8 to 2.8.0. - [Release notes](https://github.com/xunit/visualstudio.xunit/releases) - [Commits](https://github.com/xunit/visualstudio.xunit/compare/2.5.8...2.8.0) --- updated-dependencies: - dependency-name: xunit.runner.visualstudio dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj index 1ef925d..1b5d8b4 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj @@ -19,7 +19,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From cef713813fd1783a6134ee6a330c93bb802169a0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 30 Apr 2024 06:38:34 +0000 Subject: [PATCH 03/17] Bump xunit from 2.7.1 to 2.8.0 Bumps [xunit](https://github.com/xunit/xunit) from 2.7.1 to 2.8.0. - [Commits](https://github.com/xunit/xunit/compare/2.7.1...2.8.0) --- updated-dependencies: - dependency-name: xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj index 1b5d8b4..bed9370 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/Microsoft.Kiota.Http.HttpClientLibrary.Tests.csproj @@ -18,7 +18,7 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all From efc179c4d133700f6f1d79d84ce81eab8abe2cc2 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 6 May 2024 13:31:18 -0400 Subject: [PATCH 04/17] - replaces sonar login by token --- .github/workflows/sonarcloud.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index d95e204..0980388 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -73,8 +73,8 @@ jobs: CoverletOutputFormat: 'opencover' # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682 shell: pwsh run: | - ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml" + ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml" dotnet workload restore dotnet build dotnet test Microsoft.Kiota.Http.HttpClientLibrary.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0 - ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file + ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file From 39c5213153b9decb5e38c420bc94f99ad939963d Mon Sep 17 00:00:00 2001 From: ghelyar <3225358+ghelyar@users.noreply.github.com> Date: Mon, 6 May 2024 18:40:24 +0100 Subject: [PATCH 05/17] Use SocketsHttpHandler and EnableMultipleHttp2Connections as default final handler --- .../KiotaClientFactoryTests.cs | 23 ++++++++++++++++--- src/KiotaClientFactory.cs | 4 +++- 2 files changed, 23 insertions(+), 4 deletions(-) diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs index ff402ea..f3180b4 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs @@ -68,6 +68,24 @@ public void ChainHandlersCollectionAndGetFirstLinkWithMultipleHandlersSetsFinalH Assert.IsType(innerHandler.InnerHandler); } + [Fact] + public void GetDefaultHttpMessageHandlerEnablesMultipleHttp2Connections() + { + // Arrange + var proxy = new WebProxy("http://localhost:8888", false); + // Act + var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler(proxy); + // Assert + Assert.NotNull(defaultHandler); +#if NETFRAMEWORK + Assert.IsType(defaultHandler); + Assert.True(((WinHttpHandler)defaultHandler).EnableMultipleHttp2Connections); +#else + Assert.IsType(defaultHandler); + Assert.True(((SocketsHttpHandler)defaultHandler).EnableMultipleHttp2Connections); +#endif + } + [Fact] public void GetDefaultHttpMessageHandlerSetsUpProxy() { @@ -81,10 +99,9 @@ public void GetDefaultHttpMessageHandlerSetsUpProxy() Assert.IsType(defaultHandler); Assert.Equal(proxy, ((WinHttpHandler)defaultHandler).Proxy); #else - Assert.IsType(defaultHandler); - Assert.Equal(proxy, ((HttpClientHandler)defaultHandler).Proxy); + Assert.IsType(defaultHandler); + Assert.Equal(proxy, ((SocketsHttpHandler)defaultHandler).Proxy); #endif - } [Fact] diff --git a/src/KiotaClientFactory.cs b/src/KiotaClientFactory.cs index f1a9a4c..0439561 100644 --- a/src/KiotaClientFactory.cs +++ b/src/KiotaClientFactory.cs @@ -104,7 +104,9 @@ public static HttpMessageHandler GetDefaultHttpMessageHandler(IWebProxy? proxy = // If custom proxy is passed, the WindowsProxyUsePolicy will need updating // https://github.com/dotnet/runtime/blob/main/src/libraries/System.Net.Http.WinHttpHandler/src/System/Net/Http/WinHttpHandler.cs#L575 var proxyPolicy = proxy != null ? WindowsProxyUsePolicy.UseCustomProxy : WindowsProxyUsePolicy.UseWinHttpProxy; - return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.None , WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan }; + return new WinHttpHandler { Proxy = proxy, AutomaticDecompression = DecompressionMethods.None, WindowsProxyUsePolicy = proxyPolicy, SendTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveDataTimeout = System.Threading.Timeout.InfiniteTimeSpan, ReceiveHeadersTimeout = System.Threading.Timeout.InfiniteTimeSpan, EnableMultipleHttp2Connections = true }; +#elif NET5_0_OR_GREATER + return new SocketsHttpHandler { Proxy = proxy, AllowAutoRedirect = false, EnableMultipleHttp2Connections = true }; #else return new HttpClientHandler { Proxy = proxy, AllowAutoRedirect = false }; #endif From 2ad1f79ceea6e1c66202bf1720136e5631d55fc3 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 6 May 2024 13:59:00 -0400 Subject: [PATCH 06/17] - removes unnecessary parameter --- .github/workflows/sonarcloud.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 0980388..5e37678 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -77,4 +77,4 @@ jobs: dotnet workload restore dotnet build dotnet test Microsoft.Kiota.Http.HttpClientLibrary.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0 - ./.sonar/scanner/dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file + ./.sonar/scanner/dotnet-sonarscanner end \ No newline at end of file From c2f60273bd98ea64bfc44bfd3628dba2d3b5aa86 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Mon, 6 May 2024 15:58:11 -0400 Subject: [PATCH 07/17] - removes caching due to invalidation problems --- .github/workflows/sonarcloud.yml | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/.github/workflows/sonarcloud.yml b/.github/workflows/sonarcloud.yml index 5e37678..e7499e2 100644 --- a/.github/workflows/sonarcloud.yml +++ b/.github/workflows/sonarcloud.yml @@ -53,19 +53,8 @@ jobs: path: ~/.sonar/cache key: ${{ runner.os }}-sonar restore-keys: ${{ runner.os }}-sonar - - name: Cache SonarCloud scanner - id: cache-sonar-scanner - uses: actions/cache@v4 - with: - path: ./.sonar/scanner - key: ${{ runner.os }}-sonar-scanner - restore-keys: ${{ runner.os }}-sonar-scanner - name: Install SonarCloud scanner - if: steps.cache-sonar-scanner.outputs.cache-hit != 'true' - shell: pwsh - run: | - New-Item -Path ./.sonar/scanner -ItemType Directory - dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner + run: dotnet tool install dotnet-sonarscanner --create-manifest-if-needed - name: Build and analyze env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any @@ -73,8 +62,8 @@ jobs: CoverletOutputFormat: 'opencover' # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682 shell: pwsh run: | - ./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml" + dotnet tool run dotnet-sonarscanner begin /k:"microsoft_kiota-http-dotnet" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="Microsoft.Kiota.Http.HttpClientLibrary.Tests/coverage.net8.0.opencover.xml" dotnet workload restore dotnet build dotnet test Microsoft.Kiota.Http.HttpClientLibrary.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover --framework net8.0 - ./.sonar/scanner/dotnet-sonarscanner end \ No newline at end of file + dotnet tool run dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}" \ No newline at end of file From b8bd946e892d29c43d0337cdfb4f7111acb46e52 Mon Sep 17 00:00:00 2001 From: ghelyar <3225358+ghelyar@users.noreply.github.com> Date: Tue, 7 May 2024 10:31:46 +0100 Subject: [PATCH 08/17] remove unnecessary arrange from test --- .../KiotaClientFactoryTests.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs index f3180b4..72c6812 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/KiotaClientFactoryTests.cs @@ -71,10 +71,8 @@ public void ChainHandlersCollectionAndGetFirstLinkWithMultipleHandlersSetsFinalH [Fact] public void GetDefaultHttpMessageHandlerEnablesMultipleHttp2Connections() { - // Arrange - var proxy = new WebProxy("http://localhost:8888", false); // Act - var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler(proxy); + var defaultHandler = KiotaClientFactory.GetDefaultHttpMessageHandler(); // Assert Assert.NotNull(defaultHandler); #if NETFRAMEWORK From 8e24a934893747f1829b0acb96dc6e7529f0e1f7 Mon Sep 17 00:00:00 2001 From: ghelyar <3225358+ghelyar@users.noreply.github.com> Date: Tue, 7 May 2024 16:49:01 +0100 Subject: [PATCH 09/17] update version number to 1.4.1 with changelog --- src/Microsoft.Kiota.Http.HttpClientLibrary.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj index 6da462c..e62ba44 100644 --- a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj +++ b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj @@ -15,7 +15,7 @@ https://aka.ms/kiota/docs true true - 1.4.0 + 1.4.1 true From 33a7832ffc04723f23303fda565884beda19852c Mon Sep 17 00:00:00 2001 From: ghelyar <3225358+ghelyar@users.noreply.github.com> Date: Tue, 7 May 2024 16:49:17 +0100 Subject: [PATCH 10/17] changelog --- CHANGELOG.md | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6161fec..977dfdd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,16 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.4.0] - -## Added - -- KiotaClientFactory `create()` overload that accepts a list of handlers. - +## [1.4.1] - 2024-05-07 + +## Changed + +- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler. + +## [1.4.0] + +## Added + +- KiotaClientFactory `create()` overload that accepts a list of handlers. + ## [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). +- Adds `ConfigureAwait(false)` calls to async calls (https://github.com/microsoft/kiota-http-dotnet/issues/240). ## [1.3.11] - 2024-04-19 @@ -28,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 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 (https://github.com/microsoft/kiota-http-dotnet/issues/230) ## [1.3.9] - 2024-04-17 From 285203c0733b509134700040d1fd23876e460f5d Mon Sep 17 00:00:00 2001 From: ghelyar <3225358+ghelyar@users.noreply.github.com> Date: Tue, 7 May 2024 16:57:09 +0100 Subject: [PATCH 11/17] revert unintentional changes to other lines of changelog --- CHANGELOG.md | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 977dfdd..1b83185 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,22 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.4.1] - 2024-05-07 - -## Changed - -- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler. - -## [1.4.0] - -## Added - -- KiotaClientFactory `create()` overload that accepts a list of handlers. - +## [1.4.1] - 2024-05-07 + +## Changed + +- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler. + +## [1.4.0] + +## Added + +- KiotaClientFactory `create()` overload that accepts a list of handlers. + ## [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). +- Adds `ConfigureAwait(false)` calls to async calls (https://github.com/microsoft/kiota-http-dotnet/issues/240). ## [1.3.11] - 2024-04-19 @@ -34,7 +34,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## 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 (https://github.com/microsoft/kiota-http-dotnet/issues/230) ## [1.3.9] - 2024-04-17 From e4d75c92a4ba8a06378e291a5a7618ee288a080e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 7 May 2024 13:25:57 -0400 Subject: [PATCH 12/17] - code cleanup: replaces async void by async Task Signed-off-by: Vincent Biret --- .../RequestAdapterTests.cs | 34 +++++++++---------- 1 file changed, 17 insertions(+), 17 deletions(-) diff --git a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs index 8ea1fbe..cd15006 100644 --- a/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs +++ b/Microsoft.Kiota.Http.HttpClientLibrary.Tests/RequestAdapterTests.cs @@ -176,7 +176,7 @@ public async Task GetRequestMessageFromRequestInformationSetsContentHeaders() } [Fact] - public async void SendMethodDoesNotThrowWithoutUrlTemplate() + public async Task SendMethodDoesNotThrowWithoutUrlTemplate() { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -206,7 +206,7 @@ public async void SendMethodDoesNotThrowWithoutUrlTemplate() [InlineData(HttpStatusCode.NonAuthoritativeInformation)] [InlineData(HttpStatusCode.PartialContent)] [Theory] - public async void SendStreamReturnsUsableStream(HttpStatusCode statusCode) + public async Task SendStreamReturnsUsableStream(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -238,7 +238,7 @@ public async void SendStreamReturnsUsableStream(HttpStatusCode statusCode) [InlineData(HttpStatusCode.NonAuthoritativeInformation)] [InlineData(HttpStatusCode.NoContent)] [Theory] - public async void SendStreamReturnsNullForNoContent(HttpStatusCode statusCode) + public async Task SendStreamReturnsNullForNoContent(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -266,7 +266,7 @@ public async void SendStreamReturnsNullForNoContent(HttpStatusCode statusCode) [InlineData(HttpStatusCode.NoContent)] [InlineData(HttpStatusCode.PartialContent)] [Theory] - public async void SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode statusCode) + public async Task SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -292,7 +292,7 @@ public async void SendSNoContentDoesntFailOnOtherStatusCodes(HttpStatusCode stat [InlineData(HttpStatusCode.NoContent)] [InlineData(HttpStatusCode.ResetContent)] [Theory] - public async void SendReturnsNullOnNoContent(HttpStatusCode statusCode) + public async Task SendReturnsNullOnNoContent(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -321,7 +321,7 @@ public async void SendReturnsNullOnNoContent(HttpStatusCode statusCode) [InlineData(HttpStatusCode.NoContent)] [InlineData(HttpStatusCode.ResetContent)] [Theory] - public async void SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusCode statusCode) + public async Task SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -348,7 +348,7 @@ public async void SendReturnsNullOnNoContentWithContentHeaderPresent(HttpStatusC [InlineData(HttpStatusCode.Accepted)] [InlineData(HttpStatusCode.NonAuthoritativeInformation)] [Theory] - public async void SendReturnsObjectOnContent(HttpStatusCode statusCode) + public async Task SendReturnsObjectOnContent(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -379,7 +379,7 @@ public async void SendReturnsObjectOnContent(HttpStatusCode statusCode) Assert.NotNull(response); } [Fact] - public async void RetriesOnCAEResponse() + public async Task RetriesOnCAEResponse() { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -393,7 +393,7 @@ public async void 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); @@ -414,7 +414,7 @@ public async void RetriesOnCAEResponse() [InlineData(HttpStatusCode.NotFound)] [InlineData(HttpStatusCode.BadGateway)] [Theory] - public async void SetsTheApiExceptionStatusCode(HttpStatusCode statusCode) + public async Task SetsTheApiExceptionStatusCode(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -440,7 +440,7 @@ public async void 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")); @@ -449,7 +449,7 @@ public async void SetsTheApiExceptionStatusCode(HttpStatusCode statusCode) [InlineData(HttpStatusCode.NotFound)]// 4XX [InlineData(HttpStatusCode.BadGateway)]// 5XX [Theory] - public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusCode) + public async Task SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -460,7 +460,7 @@ public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC var responseMessage = new HttpResponseMessage { StatusCode = statusCode, - Content = new StringContent("{}",Encoding.UTF8,"application/json") + Content = new StringContent("{}", Encoding.UTF8, "application/json") }; return responseMessage; }); @@ -485,7 +485,7 @@ public async void 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); @@ -493,7 +493,7 @@ public async void SelectsTheXXXErrorMappingClassCorrectly(HttpStatusCode statusC } [InlineData(HttpStatusCode.BadGateway)]// 5XX [Theory] - public async void ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode) + public async Task ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode) { var mockHandler = new Mock(); var client = new HttpClient(mockHandler.Object); @@ -510,7 +510,7 @@ public async void ThrowsApiExceptionOnMissingMapping(HttpStatusCode statusCode) }); var mockParseNode = new Mock(); mockParseNode.Setup(x => x.GetObjectValue(It.IsAny>())) - .Returns(new MockError("A general error occured: "+ statusCode.ToString())); + .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); @@ -529,7 +529,7 @@ public async void 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); From 8e9013ef670fb13cc043bab7134b0bd77543f883 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 7 May 2024 13:26:09 -0400 Subject: [PATCH 13/17] - updates recommended extensions Signed-off-by: Vincent Biret --- .vscode/extensions.json | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/.vscode/extensions.json b/.vscode/extensions.json index 9a6a732..073fa2b 100644 --- a/.vscode/extensions.json +++ b/.vscode/extensions.json @@ -1,14 +1,14 @@ { - "recommendations": [ - "formulahendry.dotnet-test-explorer", - "ms-azure-devops.azure-pipelines", - "streetsidesoftware.code-spell-checker", - "editorconfig.editorconfig", - "donjayamanne.githistory", - "cschleiden.vscode-github-actions", - "github.copilot", - "github.vscode-pull-request-github", - "ms-vsliveshare.vsliveshare", - "esbenp.prettier-vscode" - ] -} \ No newline at end of file + "recommendations": [ + "ms-azure-devops.azure-pipelines", + "streetsidesoftware.code-spell-checker", + "editorconfig.editorconfig", + "donjayamanne.githistory", + "cschleiden.vscode-github-actions", + "github.copilot", + "github.vscode-pull-request-github", + "ms-vsliveshare.vsliveshare", + "esbenp.prettier-vscode", + "ms-dotnettools.vscodeintellicode-csharp" + ] +} From 4c8b4f7bcfb791d6b2a397f3ac42ccda2c9cb06e Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 14 May 2024 07:42:24 -0400 Subject: [PATCH 14/17] - updates code of conduct to the latest standard --- CODE_OF_CONDUCT.md | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md index c72a574..686e5e7 100644 --- a/CODE_OF_CONDUCT.md +++ b/CODE_OF_CONDUCT.md @@ -1,9 +1,10 @@ -# Microsoft Open Source Code of Conduct - -This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). - -Resources: - -- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) -- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) -- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns +# Microsoft Open Source Code of Conduct + +This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/). + +Resources: + +- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/) +- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) +- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns +- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support) From b9044dc69ddd3873de5b8c0706b46a78c3da57e3 Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Sat, 18 May 2024 21:25:35 +0200 Subject: [PATCH 15/17] Returning delegetion types for DI integration Fixed #254 --- src/KiotaClientFactory.cs | 55 +++++++++++++------ .../Options/UriReplacementHandlerOption.cs | 7 +++ 2 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/KiotaClientFactory.cs b/src/KiotaClientFactory.cs index 0439561..99c00ed 100644 --- a/src/KiotaClientFactory.cs +++ b/src/KiotaClientFactory.cs @@ -28,21 +28,21 @@ public static HttpClient Create(HttpMessageHandler? finalHandler = null) var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), defaultHandlers.ToArray()); return handler != null ? new HttpClient(handler) : new HttpClient(); } - - /// - /// Initializes the with a custom middleware pipeline. - /// - /// The instances to create the from. - /// The final in the http pipeline. Can be configured for proxies, auto-decompression and auto-redirects - /// The with the custom handlers. - public static HttpClient Create(IList handlers, HttpMessageHandler? finalHandler = null) - { - if(handlers == null || !handlers.Any()) - return Create(finalHandler); - var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), handlers.ToArray()); - return handler != null ? new HttpClient(handler) : new HttpClient(); - } - + + /// + /// Initializes the with a custom middleware pipeline. + /// + /// The instances to create the from. + /// The final in the http pipeline. Can be configured for proxies, auto-decompression and auto-redirects + /// The with the custom handlers. + public static HttpClient Create(IList handlers, HttpMessageHandler? finalHandler = null) + { + if(handlers == null || !handlers.Any()) + return Create(finalHandler); + var handler = ChainHandlersCollectionAndGetFirstLink(finalHandler ?? GetDefaultHttpMessageHandler(), handlers.ToArray()); + return handler != null ? new HttpClient(handler) : new HttpClient(); + } + /// /// Creates a default set of middleware to be used by the . /// @@ -51,7 +51,7 @@ public static IList CreateDefaultHandlers() { return new List { - //add the default middlewares as they are ready + //add the default middlewares as they are ready, and add them to the list above as well new UriReplacementHandler(), new RetryHandler(), new RedirectHandler(), @@ -60,6 +60,25 @@ public static IList CreateDefaultHandlers() new HeadersInspectionHandler(), }; } + + /// + /// Gets the default handler types. + /// + /// A list of all the default handlers + /// Order matters + public static IList GetDefaultHandlerTypes() + { + return new List + { + typeof(UriReplacementHandler), + typeof(RetryHandler), + typeof(RedirectHandler), + typeof(ParametersNameDecodingHandler), + typeof(UserAgentHandler), + typeof(HeadersInspectionHandler), + }; + } + /// /// Creates a to use for the from the provided instances. Order matters. /// @@ -81,7 +100,7 @@ public static IList CreateDefaultHandlers() } } if(finalHandler != null) - handlers[handlers.Length-1].InnerHandler = finalHandler; + handlers[handlers.Length - 1].InnerHandler = finalHandler; return handlers[0];//first } /// @@ -91,7 +110,7 @@ public static IList CreateDefaultHandlers() /// The created . public static DelegatingHandler? ChainHandlersCollectionAndGetFirstLink(params DelegatingHandler[] handlers) { - return ChainHandlersCollectionAndGetFirstLink(null,handlers); + return ChainHandlersCollectionAndGetFirstLink(null, handlers); } /// /// Gets a default Http Client handler with the appropriate proxy configurations diff --git a/src/Middleware/Options/UriReplacementHandlerOption.cs b/src/Middleware/Options/UriReplacementHandlerOption.cs index b0a14e7..6198111 100644 --- a/src/Middleware/Options/UriReplacementHandlerOption.cs +++ b/src/Middleware/Options/UriReplacementHandlerOption.cs @@ -43,6 +43,13 @@ public UriReplacementHandlerOption(bool isEnabled, IEnumerable + /// Creates a new instance of UriReplacementOption with no replacements. + /// + /// Whether replacement is enabled. + /// Replacement is disabled by default. + public UriReplacementHandlerOption(bool isEnabled = false) : this(isEnabled, Array.Empty>()) { } + /// public bool IsEnabled() { From a47e2a84acce352c07ad7620b0a75a6feb168fbb Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Sat, 18 May 2024 21:30:40 +0200 Subject: [PATCH 16/17] its below --- src/KiotaClientFactory.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/KiotaClientFactory.cs b/src/KiotaClientFactory.cs index 99c00ed..96c1eb5 100644 --- a/src/KiotaClientFactory.cs +++ b/src/KiotaClientFactory.cs @@ -51,7 +51,7 @@ public static IList CreateDefaultHandlers() { return new List { - //add the default middlewares as they are ready, and add them to the list above as well + //add the default middlewares as they are ready, and add them to the list below as well new UriReplacementHandler(), new RetryHandler(), new RedirectHandler(), From 2564189c61d7a2f31cd5403253ef24401068253a Mon Sep 17 00:00:00 2001 From: Stephan van Rooij <1292510+svrooij@users.noreply.github.com> Date: Tue, 21 May 2024 19:53:16 +0200 Subject: [PATCH 17/17] bump version --- CHANGELOG.md | 28 +++++++++++-------- ...rosoft.Kiota.Http.HttpClientLibrary.csproj | 2 +- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 1b83185..2b5048a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,18 +7,22 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] -## [1.4.1] - 2024-05-07 - -## Changed - -- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler. - -## [1.4.0] - -## Added - -- KiotaClientFactory `create()` overload that accepts a list of handlers. - +### Added + +- `GetDefaultHandlerTypes` added to `KiotaClientFactory` if you're creating your own `HttpClient` and still want to use the default handlers. + +## [1.4.1] - 2024-05-07 + +## Changed + +- Use `SocketsHttpHandler` with `EnableMultipleHttp2Connections` as default HTTP message handler. + +## [1.4.0] + +## Added + +- KiotaClientFactory `create()` overload that accepts a list of handlers. + ## [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) diff --git a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj index e62ba44..8f30e5b 100644 --- a/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj +++ b/src/Microsoft.Kiota.Http.HttpClientLibrary.csproj @@ -15,7 +15,7 @@ https://aka.ms/kiota/docs true true - 1.4.1 + 1.4.2 true