Skip to content

Commit

Permalink
Switch to net 6 & improve cancellation token propergation
Browse files Browse the repository at this point in the history
  • Loading branch information
thompson-tomo committed Jul 18, 2024
1 parent 47f9528 commit 3818404
Show file tree
Hide file tree
Showing 5 changed files with 99 additions and 16 deletions.
25 changes: 21 additions & 4 deletions Consul/Client_DeleteRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,13 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)
var response = await Client.HttpClient.SendAsync(message, ct).ConfigureAwait(false);

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -146,7 +151,13 @@ public async Task<WriteResult> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -246,7 +257,13 @@ public async Task<WriteResult> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down
24 changes: 21 additions & 3 deletions Consul/Client_GetRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,13 @@ public async Task<QueryResult<TOut>> Execute(CancellationToken ct)

ParseQueryHeaders(response, result);
result.StatusCode = response.StatusCode;
ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);


Func<bool> isSpecialStatusCode = () =>
Expand Down Expand Up @@ -131,7 +137,13 @@ public async Task<QueryResult<Stream>> ExecuteStreaming(CancellationToken ct)

ParseQueryHeaders(response, result as QueryResult<TOut>);
result.StatusCode = response.StatusCode;
ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

result.Response = ResponseStream;

Expand Down Expand Up @@ -330,7 +342,13 @@ public async Task<QueryResult<string>> Execute(CancellationToken ct)
var response = await Client.HttpClient.SendAsync(message, ct).ConfigureAwait(false);

result.StatusCode = response.StatusCode;
ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

Func<bool> isSpecialStatusCode = () =>
{
Expand Down
32 changes: 28 additions & 4 deletions Consul/Client_PostRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,13 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -170,7 +176,13 @@ public async Task<WriteResult> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -271,7 +283,13 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -361,7 +379,13 @@ public async Task<WriteResult<string>> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down
32 changes: 28 additions & 4 deletions Consul/Client_PutRequests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,13 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -145,7 +151,13 @@ public async Task<WriteResult> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -245,7 +257,13 @@ public async Task<WriteResult> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (response.StatusCode != HttpStatusCode.NotFound && !response.IsSuccessStatusCode)
{
Expand Down Expand Up @@ -346,7 +364,13 @@ public async Task<WriteResult<TOut>> Execute(CancellationToken ct)

result.StatusCode = response.StatusCode;

ResponseStream = await response.Content.ReadAsStreamAsync().ConfigureAwait(false);
ResponseStream = await response.Content
#if !NET6_0_OR_GREATER
.ReadAsStreamAsync()
#else
.ReadAsStreamAsync(ct)
#endif
.ConfigureAwait(false);

if (!response.IsSuccessStatusCode && (
(response.StatusCode != HttpStatusCode.NotFound && typeof(TOut) != typeof(TxnResponse)) ||
Expand Down
2 changes: 1 addition & 1 deletion Consul/Consul.csproj
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>netstandard2.0;net461;netstandard2.1</TargetFrameworks>
<TargetFrameworks>netstandard2.0;net461;net6</TargetFrameworks>
<Authors>PlayFab,$(Authors)</Authors>
<Copyright>Copyright 2015-2018 PlayFab Inc.; $(Copyright)</Copyright>
<Description>Consul.NET is a .NET client library for the Consul HTTP API</Description>
Expand Down

0 comments on commit 3818404

Please sign in to comment.