-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHttpDownloadOptions.cs
More file actions
95 lines (82 loc) · 3.2 KB
/
Copy pathHttpDownloadOptions.cs
File metadata and controls
95 lines (82 loc) · 3.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
using System.Net;
using GeneralUpdate.Avalonia.Android.Abstractions;
namespace GeneralUpdate.Avalonia.Android.Models;
/// <summary>
/// Configures HTTP transport behavior for update downloads:
/// SSL/TLS certificate validation, timeouts, proxy, retry, and authentication.
/// <para>
/// When provided to <see cref="GeneralUpdateBootstrap.CreateDefault"/>,
/// the library constructs an internal <see cref="HttpClient"/> from these settings.
/// When null, the existing behavior is preserved (bare HttpClient, no auth, system SSL).
/// </para>
/// </summary>
public sealed record HttpDownloadOptions
{
/// <summary>
/// Custom SSL/TLS certificate validation policy.
/// Defaults to null, which uses the system's default certificate validation.
/// Set to <see cref="Services.AllowAllSslValidationPolicy"/> for self-signed certificates
/// in development environments only.
/// </summary>
public ISslValidationPolicy? SslValidationPolicy { get; init; }
/// <summary>
/// Timeout for individual HTTP requests (HEAD probes, etc.).
/// Default is 30 seconds.
/// </summary>
public TimeSpan RequestTimeout { get; init; } = TimeSpan.FromSeconds(30);
/// <summary>
/// Overall timeout for the entire download operation.
/// Default is 10 minutes.
/// </summary>
public TimeSpan DownloadTimeout { get; init; } = TimeSpan.FromMinutes(10);
/// <summary>
/// Optional web proxy for HTTP requests.
/// When set, <see cref="UseProxy"/> must also be true for the proxy to take effect.
/// </summary>
public IWebProxy? Proxy { get; init; }
/// <summary>
/// Whether to use the configured <see cref="Proxy"/>.
/// Default is false.
/// </summary>
public bool UseProxy { get; init; }
/// <summary>
/// Maximum number of retry attempts for transient failures.
/// Default is 3 (meaning 1 initial attempt + 2 retries).
/// Set to 1 to disable retry.
/// </summary>
public int MaxRetryAttempts { get; init; } = 3;
/// <summary>
/// Base delay for exponential backoff retry.
/// Actual delays are: baseDelay * 2^attempt.
/// Default is 1 second.
/// </summary>
public TimeSpan RetryBaseDelay { get; init; } = TimeSpan.FromSeconds(1);
/// <summary>
/// Global authentication provider applied to all download requests.
/// Per-package authentication on <see cref="UpdatePackageInfo"/> takes precedence.
/// </summary>
public IHttpAuthProvider? AuthProvider { get; init; }
/// <summary>
/// Builds an <see cref="HttpClientHandler"/> from the configured options.
/// Applies SSL validation policy and proxy settings.
/// </summary>
internal HttpClientHandler BuildHandler()
{
var handler = new HttpClientHandler();
if (SslValidationPolicy != null)
{
handler.ServerCertificateCustomValidationCallback =
(_, cert, chain, errors) => SslValidationPolicy.ValidateCertificate(cert, chain, errors);
}
if (UseProxy && Proxy != null)
{
handler.Proxy = Proxy;
handler.UseProxy = true;
}
else
{
handler.UseProxy = false;
}
return handler;
}
}