Skip to content

Commit 167e7ff

Browse files
committed
Timeouts and HttpCompletionOption.ResponseHeadersRead updated
1 parent ed78923 commit 167e7ff

File tree

2 files changed

+24
-6
lines changed

2 files changed

+24
-6
lines changed

Common/Http/SatService.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,8 +81,11 @@ protected async Task<SatResponse> SendRequestAsync(string url, string action, st
8181
{
8282
LogRequest(request, url, action, payload);
8383
84+
// Use ResponseHeadersRead to complete as soon as headers are received, allowing early error detection
85+
// This prevents waiting for the entire response body before detecting HTTP errors, which can help
86+
// reduce timeout issues when the SAT server is slow to generate/transmit large ZIP packages
8487
using var response =
85-
await _httpClient.SendAsync(request, HttpCompletionOption.ResponseContentRead, cancellationToken);
88+
await _httpClient.SendAsync(request, HttpCompletionOption.ResponseHeadersRead, cancellationToken);
8689
var responseContent = await response.Content.ReadAsStringAsync(cancellationToken);
8790
8891
LogResponse(response, responseContent, url, action);

DownloaderExtensions.cs

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,26 @@ public static TEnum ToEnumElement<TEnum>(this string code) where TEnum : struct,
171171
/// <returns>The service collection for chaining</returns>
172172
public static IServiceCollection AddXmlDownloader(this IServiceCollection services)
173173
{
174-
// Register HttpClient factory for SAT services
175-
services.AddHttpClient<IAuthService, AuthService>();
176-
services.AddHttpClient<IQueryService, QueryService>();
177-
services.AddHttpClient<IVerifyService, VerifyService>();
178-
services.AddHttpClient<IDownloadService, DownloadService>();
174+
// Register HttpClient factory for SAT services with appropriate timeouts
175+
services.AddHttpClient<IAuthService, AuthService>(client =>
176+
{
177+
client.Timeout = TimeSpan.FromMinutes(3);
178+
});
179+
180+
services.AddHttpClient<IQueryService, QueryService>(client =>
181+
{
182+
client.Timeout = TimeSpan.FromMinutes(3);
183+
});
184+
185+
services.AddHttpClient<IVerifyService, VerifyService>(client =>
186+
{
187+
client.Timeout = TimeSpan.FromMinutes(3);
188+
});
189+
190+
services.AddHttpClient<IDownloadService, DownloadService>(client =>
191+
{
192+
client.Timeout = TimeSpan.FromMinutes(7);
193+
});
179194

180195
// Register non-HTTP services as scoped
181196
services.AddScoped<IFileStorageService, FileStorageService>();

0 commit comments

Comments
 (0)