-
Notifications
You must be signed in to change notification settings - Fork 0
V2.5.0 #16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
V2.5.0 #16
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
8fe520f
Refactor error handling; add transient handler & base class
Khojasteh a89c70b
Update tests for .NET 10, NUnit 4.4, and new APIs
Khojasteh d2b19c3
Update workflow to .NET 10 and set keep_files to false
Khojasteh cbe25cc
Update copyright year to 2025 in all source files
Khojasteh 1ce46b9
Bump version to 2.5.0 in project file
Khojasteh File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Kampute.HttpClient.DataContract/HttpRestClientXmlExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Kampute.HttpClient.NewtonsoftJson/HttpRestClientJsonExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Kampute.HttpClient.NewtonsoftJson/JsonContentDeserializer.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/Kampute.HttpClient/Content/Compression/Abstracts/NamespaceDoc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
13 changes: 13 additions & 0 deletions
13
src/Kampute.HttpClient/ErrorHandlers/Abstracts/NamespaceDoc.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| // Copyright (C) 2025 Kampute | ||
| // | ||
| // This file is part of the Kampute.HttpClient package and is released under the terms of the MIT license. | ||
| // See the LICENSE file in the project root for the full license text. | ||
|
|
||
| namespace Kampute.HttpClient.ErrorHandlers.Abstracts | ||
| { | ||
| /// <summary> | ||
| /// This namespace contains abstract classes for handling transient HTTP error responses by implementing | ||
| /// backoff and retry strategies. | ||
| /// </summary> | ||
| internal static class NamespaceDoc { } | ||
| } |
125 changes: 125 additions & 0 deletions
125
src/Kampute.HttpClient/ErrorHandlers/Abstracts/RetryableHttpErrorHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| // Copyright (C) 2025 Kampute | ||
| // | ||
| // This file is part of the Kampute.HttpClient package and is released under the terms of the MIT license. | ||
| // See the LICENSE file in the project root for the full license text. | ||
|
|
||
| namespace Kampute.HttpClient.ErrorHandlers.Abstracts | ||
| { | ||
| using Kampute.HttpClient.Interfaces; | ||
| using System; | ||
| using System.Net; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
|
|
||
| /// <summary> | ||
| /// Provides the base functionality for handling HTTP responses with transient error status codes by attempting to back off and | ||
| /// retry the request according to a specified or default backoff strategy. | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This handler class is designed to be extended for specific transient error status codes. It offers a mechanism to respond to | ||
| /// transient HTTP errors by retrying the request after a delay. The delay duration and retry logic can be customized through the | ||
| /// <see cref="OnBackoffStrategy"/> delegate. | ||
| /// </remarks> | ||
| /// <seealso cref="HttpRestClient.ErrorHandlers"/> | ||
| /// <seealso cref="HttpRestClient.BackoffStrategy"/> | ||
| public abstract class RetryableHttpErrorHandler : IHttpErrorHandler | ||
| { | ||
| /// <summary> | ||
| /// A delegate that allows customization of the backoff strategy when responses with transient error status codes are received. | ||
| /// </summary> | ||
| /// <value> | ||
| /// A function that takes an <see cref="HttpResponseErrorContext"/> and an optional <see cref="DateTimeOffset"/> representing | ||
| /// the suggested retry time, and returns an <see cref="IHttpBackoffProvider"/> to be used for the retry operation. | ||
| /// </value> | ||
| /// <remarks> | ||
| /// <para> | ||
| /// If this delegate is set and returns an <see cref="IHttpBackoffProvider"/>, the returned strategy is used for the retry operation. | ||
| /// If it is not set, or returns <see langword="null"/>, a default behavior is applied. | ||
| /// </para> | ||
| /// <para> | ||
| /// The delegate receives the following parameters: | ||
| /// <list type="bullet"> | ||
| /// <item> | ||
| /// <term>context</term> | ||
| /// <description> | ||
| /// Provides context about the HTTP response that indicates a transient error. It is encapsulated within an <see cref="HttpResponseErrorContext"/> | ||
| /// instance, allowing for an informed decision on the retry strategy. | ||
| /// </description> | ||
| /// </item> | ||
| /// <item> | ||
| /// <term>retryTime</term> | ||
| /// <description> | ||
| /// Advises on the next retry attempt timing as a <see cref="DateTimeOffset"/> value if the response suggests one. If the response | ||
| /// does not include a suggested retry time, the value will be <see langword="null"/>. | ||
| /// </description> | ||
| /// </item> | ||
| /// </list> | ||
| /// </para> | ||
| /// </remarks> | ||
| public Func<HttpResponseErrorContext, DateTimeOffset?, IHttpBackoffProvider?>? OnBackoffStrategy { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Determines whether this handler can process the specified HTTP status code. | ||
| /// </summary> | ||
| /// <param name="statusCode">The HTTP status code to evaluate.</param> | ||
| /// <returns><see langword="true"/> if the handler can process the status code; otherwise, <see langword="false"/>.</returns> | ||
| public abstract bool CanHandle(HttpStatusCode statusCode); | ||
|
|
||
| /// <summary> | ||
| /// Extracts the suggested retry time from the HTTP response's header, if present. | ||
| /// </summary> | ||
| /// <param name="ctx">The context containing information about the HTTP response.</param> | ||
| /// <returns>The suggested <see cref="DateTimeOffset"/> to retry the request, or <see langword="null"/> if the header is not present.</returns> | ||
| /// <exception cref="ArgumentNullException">Thrown if <paramref name="ctx"/> is <see langword="null"/>.</exception> | ||
| protected virtual DateTimeOffset? GetSuggestedRetryTime(HttpResponseErrorContext ctx) | ||
| { | ||
| if (ctx is null) | ||
| throw new ArgumentNullException(nameof(ctx)); | ||
|
|
||
| ctx.Response.Headers.TryExtractRetryAfterTime(out var retryTime); | ||
| return retryTime; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Provides the default backoff strategy when no custom strategy is specified. | ||
| /// </summary> | ||
| /// <param name="ctx">The context containing information about the HTTP response.</param> | ||
| /// <param name="retryTime">The suggested retry time, if any.</param> | ||
| /// <returns>An <see cref="IHttpBackoffProvider"/> representing the default backoff strategy.</returns> | ||
| /// <exception cref="ArgumentNullException">Thrown if <paramref name="ctx"/> is <see langword="null"/>.</exception> | ||
| protected virtual IHttpBackoffProvider GetDefaultStrategy(HttpResponseErrorContext ctx, DateTimeOffset? retryTime) | ||
| { | ||
| if (ctx is null) | ||
| throw new ArgumentNullException(nameof(ctx)); | ||
|
|
||
| return retryTime.HasValue ? BackoffStrategies.Once(retryTime.Value) : ctx.Client.BackoffStrategy; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Creates a scheduler for retrying the failed request based on the error context. | ||
| /// </summary> | ||
| /// <param name="ctx">The context containing information about the HTTP response that indicates a failure.</param> | ||
| /// <returns>An <see cref="IRetryScheduler"/> that schedules the retry attempts.</returns> | ||
| /// <exception cref="ArgumentNullException">Thrown if <paramref name="ctx"/> is <see langword="null"/>.</exception> | ||
| /// <remarks> | ||
| /// The method uses <see cref="OnBackoffStrategy"/> when available. If the delegate is not provided or returns | ||
| /// <see langword="null"/>, and the response includes a suggested retry time, a single retry at that time is used. | ||
| /// Otherwise the client's default backoff strategy is used. | ||
| /// </remarks> | ||
| protected virtual IRetryScheduler? CreateScheduler(HttpResponseErrorContext ctx) | ||
| { | ||
| if (ctx is null) | ||
| throw new ArgumentNullException(nameof(ctx)); | ||
|
|
||
| var retryTime = GetSuggestedRetryTime(ctx); | ||
| var strategy = OnBackoffStrategy?.Invoke(ctx, retryTime) ?? GetDefaultStrategy(ctx, retryTime); | ||
| return strategy.CreateScheduler(ctx); | ||
| } | ||
|
|
||
| /// <inheritdoc/> | ||
| Task<HttpErrorHandlerResult> IHttpErrorHandler.DecideOnRetryAsync(HttpResponseErrorContext ctx, CancellationToken cancellationToken) | ||
| { | ||
| return ctx.ScheduleRetryAsync(CreateScheduler, cancellationToken); | ||
| } | ||
| } | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/Kampute.HttpClient/ErrorHandlers/DynamicHttpErrorHandler.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.