Skip to content

Commit

Permalink
Fix wrong parameter type of the delegate using in HttpError401Handler (
Browse files Browse the repository at this point in the history
…#9)

Co-authored-by: Kambiz Khojasteh <[email protected]>
  • Loading branch information
kampute and Khojasteh authored May 6, 2024
1 parent b552dc7 commit f4fec3d
Show file tree
Hide file tree
Showing 8 changed files with 44 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Kampute.HttpClient.DataContract</Title>
<Description>This package is an extension package for Kampute.HttpClient, enhancing it to manage application/xml content types, using DataContractSerializer for serialization and deserialization of XML responses and payloads.</Description>
<Authors>Kambiz Khojasteh</Authors>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Company>Kampute</Company>
<Copyright>Copyright (c) 2024 Kampute</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Kampute.HttpClient.Json/Kampute.HttpClient.Json.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Kampute.HttpClient.Json</Title>
<Description>This package is an extension package for Kampute.HttpClient, enhancing it to manage application/json content types, using System.Text.Json library for serialization and deserialization of JSON responses and payloads.</Description>
<Authors>Kambiz Khojasteh</Authors>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Company>Kampute</Company>
<Copyright>Copyright (c) 2024 Kampute</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Kampute.HttpClient.NewtonsoftJson</Title>
<Description>This package is an extension package for Kampute.HttpClient, enhancing it to manage application/json content types, using Newtonsoft.Json library for serialization and deserialization of JSON responses and payloads.</Description>
<Authors>Kambiz Khojasteh</Authors>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Company>Kampute</Company>
<Copyright>Copyright (c) 2024 Kampute</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
2 changes: 1 addition & 1 deletion src/Kampute.HttpClient.Xml/Kampute.HttpClient.Xml.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Kampute.HttpClient.Xml</Title>
<Description>This package is an extension package for Kampute.HttpClient, enhancing it to manage application/xml content types, using XmlSerializer for serialization and deserialization of XML responses and payloads.</Description>
<Authors>Kambiz Khojasteh</Authors>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Company>Kampute</Company>
<Copyright>Copyright (c) 2024 Kampute</Copyright>
<LangVersion>latest</LangVersion>
Expand Down
14 changes: 9 additions & 5 deletions src/Kampute.HttpClient/ErrorHandlers/HttpError401Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ namespace Kampute.HttpClient.ErrorHandlers
/// <seealso cref="HttpRestClient.ErrorHandlers"/>
public class HttpError401Handler : IHttpErrorHandler, IDisposable
{
private readonly Func<HttpRequestErrorContext, CancellationToken, Task<AuthenticationHeaderValue?>> _asyncAuthenticator;
private readonly Func<HttpResponseErrorContext, CancellationToken, Task<AuthenticationHeaderValue?>> _asyncAuthenticator;
private readonly AsyncUpdateThrottle<AuthenticationHeaderValue?> _lastAuthorization;

/// <summary>
Expand All @@ -55,20 +55,24 @@ public class HttpError401Handler : IHttpErrorHandler, IDisposable
/// <list type="bullet">
/// <item>
/// <term>context</term>
/// <description>Provides context about the HTTP request resulting in a '401 Unauthorized' response. It is encapsulated within an
/// <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on authentication.</description>
/// <description>
/// Provides context about the HTTP response indicating a '401 Unauthorized' error. It is encapsulated within
/// an <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on authentication.
/// </description>
/// </item>
/// <item>
/// <term>cancellationToken</term>
/// <description>A <see cref="CancellationToken"/> for canceling the operation.</description>
/// <description>
/// A <see cref="CancellationToken"/> for canceling the operation.
/// </description>
/// </item>
/// </list>
/// The delegate should return a task resolving to an instance of <see cref="AuthenticationHeaderValue"/> containing the authorization details
/// necessary for subsequent requests if authentication can be successfully completed. If the authentication process fails, the delegate should
/// return <c>null</c>.
/// </param>
/// <exception cref="ArgumentNullException">Thrown if <paramref name="asyncAuthenticator"/> is <c>null</c>.</exception>
public HttpError401Handler(Func<HttpRequestErrorContext, CancellationToken, Task<AuthenticationHeaderValue?>> asyncAuthenticator)
public HttpError401Handler(Func<HttpResponseErrorContext, CancellationToken, Task<AuthenticationHeaderValue?>> asyncAuthenticator)
{
_asyncAuthenticator = asyncAuthenticator ?? throw new ArgumentNullException(nameof(asyncAuthenticator));
_lastAuthorization = new(null);
Expand Down
26 changes: 15 additions & 11 deletions src/Kampute.HttpClient/ErrorHandlers/HttpError429Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,21 @@ public class HttpError429Handler : IHttpErrorHandler
/// <para>
/// The delegate receives the following parameters:
/// <list type="bullet">
/// <item>
/// <term>context</term>
/// <description>Provides context about the HTTP request resulting in a '429 Too Many Requests' response. It is encapsulated
/// within an <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on the retry strategy.</description>
/// </item>
/// <item>
/// <term>resetTime</term>
/// <description>Indicates the time when the rate limit will be lifted as a <see cref="DateTimeOffset"/> value. If the server specifies
/// a reset time via response headers, this parameter provides that time, allowing the client to know when to resume requests. If the
/// server does not specify a reset time, the value will be <c>null</c>.</description>
/// </item>
/// <item>
/// <term>context</term>
/// <description>
/// Provides context about the HTTP response indicating a '429 Too Many Requests' error. It is encapsulated within
/// an <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on the retry strategy.
/// </description>
/// </item>
/// <item>
/// <term>resetTime</term>
/// <description>
/// Indicates the time when the rate limit will be lifted as a <see cref="DateTimeOffset"/> value. If the server specifies
/// a reset time via response headers, this parameter provides that time, allowing the client to know when to resume requests.
/// If the server does not specify a reset time, the value will be <c>null</c>.
/// </description>
/// </item>
/// </list>
/// </para>
/// </remarks>
Expand Down
26 changes: 15 additions & 11 deletions src/Kampute.HttpClient/ErrorHandlers/HttpError503Handler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,17 +38,21 @@ public class HttpError503Handler : IHttpErrorHandler
/// <para>
/// The delegate receives the following parameters:
/// <list type="bullet">
/// <item>
/// <term>context</term>
/// <description>Provides context about the HTTP request resulting in a '503 Service Unavailable' response. It is encapsulated
/// within an <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on the retry strategy.</description>
/// </item>
/// <item>
/// <term>retryAfter</term>
/// <description>Advises on the next retry attempt timing as a <see cref="DateTimeOffset"/> value. If the response includes a
/// <c>Retry-After</c> header, this parameter reflects its value, suggesting an optimal time to retry. If the header is missing,
/// the value is <c>null</c>, indicating no specific suggestion from the server.</description>
/// </item>
/// <item>
/// <term>context</term>
/// <description>
/// Provides context about the HTTP responce indicating a '503 Service Unavailable' error. It is encapsulated within
/// an <see cref="HttpResponseErrorContext"/> instance, allowing for an informed decision on the retry strategy.
/// </description>
/// </item>
/// <item>
/// <term>retryAfter</term>
/// <description>
/// Advises on the next retry attempt timing as a <see cref="DateTimeOffset"/> value. If the response includes a <c>Retry-After</c>
/// header, this parameter reflects its value, suggesting an optimal time to retry. If the header is missing, the value is <c>null</c>,
/// indicating no specific suggestion from the server.
/// </description>
/// </item>
/// </list>
/// </para>
/// </remarks>
Expand Down
2 changes: 1 addition & 1 deletion src/Kampute.HttpClient/Kampute.HttpClient.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<Title>Kampute.HttpClient</Title>
<Description>Kampute.HttpClient is a versatile and lightweight .NET library that simplifies RESTful API communication. Its core HttpRestClient class provides a streamlined approach to HTTP interactions, offering advanced features such as flexible serialization/deserialization, robust error handling, configurable backoff strategies, and detailed request-response processing. Striking a balance between simplicity and extensibility, Kampute.HttpClient empowers developers with a powerful yet easy-to-use client for seamless API integration across a wide range of .NET applications.</Description>
<Authors>Kambiz Khojasteh</Authors>
<Version>2.1.0</Version>
<Version>2.1.1</Version>
<Company>Kampute</Company>
<Copyright>Copyright (c) 2024 Kampute</Copyright>
<LangVersion>latest</LangVersion>
Expand Down

0 comments on commit f4fec3d

Please sign in to comment.