feat: add HTTP/HTTPS compatibility and multiple authentication methods#15
Merged
Conversation
Add authentication providers (Bearer, Basic, ApiKey, HMAC), SSL validation policies, retry with exponential backoff, download timeout, and proxy support. All new APIs are backward-compatible with existing code. New: - IHttpAuthProvider / ISslValidationPolicy interfaces - AuthScheme enum (Hmac/Bearer/ApiKey/Basic) - 5 auth providers + HttpAuthProviderFactory - StrictSslValidationPolicy / AllowAllSslValidationPolicy - HttpDownloadOptions configuration record - Per-package auth fields on UpdatePackageInfo - Auth injection, retry, and timeout in HttpResumableApkDownloader Closes #14 Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
This PR extends GeneralUpdate.Avalonia.Android’s HTTP download pipeline to support configurable SSL validation, proxy, timeouts/retry behavior, and multiple authentication schemes (Bearer/Basic/ApiKey/HMAC), while keeping the existing API path working when no new options are provided.
Changes:
- Added HTTP configuration model (
HttpDownloadOptions) plus SSL validation and auth provider abstractions/implementations. - Updated
HttpResumableApkDownloaderto inject auth into requests, add retry logic, and support internalHttpClientownership/disposal. - Extended
GeneralUpdateBootstrap.CreateDefault(...)to accept optional HTTP options, and ensured downloader disposal fromAndroidBootstrap.
Reviewed changes
Copilot reviewed 11 out of 11 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| tests/GeneralUpdate.Avalonia.Android.Tests/GeneralUpdate.Avalonia.Android.Tests.csproj | Links the new AuthScheme enum into the test project build. |
| src/GeneralUpdate.Avalonia.Android/Services/SslValidationPolicies.cs | Adds strict and permissive SSL certificate validation policy implementations. |
| src/GeneralUpdate.Avalonia.Android/Services/HttpResumableApkDownloader.cs | Adds auth injection, retry, download timeout handling, and IDisposable ownership of an internally-created HttpClient. |
| src/GeneralUpdate.Avalonia.Android/Services/AuthProviders.cs | Introduces multiple auth providers and a factory to build them from configuration. |
| src/GeneralUpdate.Avalonia.Android/Services/AndroidBootstrap.cs | Disposes downloader if it implements IDisposable. |
| src/GeneralUpdate.Avalonia.Android/Models/UpdatePackageInfo.cs | Adds per-package authentication configuration fields. |
| src/GeneralUpdate.Avalonia.Android/Models/HttpDownloadOptions.cs | Adds HTTP transport configuration (SSL, proxy, retry, timeouts, auth provider). |
| src/GeneralUpdate.Avalonia.Android/GeneralUpdateBootstrap.cs | Adds optional HttpDownloadOptions parameter and wires it into downloader creation. |
| src/GeneralUpdate.Avalonia.Android/Enums/AuthScheme.cs | Adds supported authentication scheme enum. |
| src/GeneralUpdate.Avalonia.Android/Abstractions/ISslValidationPolicy.cs | Adds SSL validation policy abstraction. |
| src/GeneralUpdate.Avalonia.Android/Abstractions/IHttpAuthProvider.cs | Adds HTTP auth provider abstraction. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+50
to
+53
| var handler = httpOptions.BuildHandler(); | ||
| _httpClient = new HttpClient(handler, disposeHandler: true); | ||
| _globalAuthProvider = httpOptions.AuthProvider; | ||
| _ownsClient = true; |
Comment on lines
+241
to
+261
| IHttpAuthProvider? provider = null; | ||
|
|
||
| // Per-package auth takes precedence | ||
| if (packageInfo.AuthScheme.HasValue) | ||
| { | ||
| provider = HttpAuthProviderFactory.Create( | ||
| packageInfo.AuthScheme.Value, | ||
| packageInfo.AuthToken, | ||
| packageInfo.AuthSecretKey, | ||
| packageInfo.BasicUsername, | ||
| packageInfo.BasicPassword); | ||
| } | ||
| else if (_globalAuthProvider != null) | ||
| { | ||
| provider = _globalAuthProvider; | ||
| } | ||
|
|
||
| if (provider != null) | ||
| { | ||
| await provider.ApplyAuthAsync(request, cancellationToken).ConfigureAwait(false); | ||
| } |
Comment on lines
+25
to
+29
| /// <summary> | ||
| /// Timeout for individual HTTP requests (HEAD probes, etc.). | ||
| /// Default is 30 seconds. | ||
| /// </summary> | ||
| public TimeSpan RequestTimeout { get; init; } = TimeSpan.FromSeconds(30); |
- Set _ownsClient = false in public constructor (prevents disposing external client) - Set HttpClient.Timeout = InfiniteTimeSpan when created internally (timeout managed via CancellationTokenSource) - Fall back to global auth provider when per-package AuthScheme has missing credentials + log warning - Wire RequestTimeout into HEAD probe request (separate from DownloadTimeout) - Simplify Enums.AuthScheme? to AuthScheme? (using already imported) Co-Authored-By: Claude <noreply@anthropic.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Adds HTTP/HTTPS compatibility features (SSL validation, proxy, timeouts, retry) and multiple authentication methods (Bearer, Basic, ApiKey, HMAC) to GeneralUpdate.Avalonia.Android.
Changes
New files (6)
IHttpAuthProvider+ISslValidationPolicyinterfacesAuthSchemeenum (Hmac/Bearer/ApiKey/Basic)HttpAuthProviderFactoryStrictSslValidationPolicy/AllowAllSslValidationPolicyHttpDownloadOptionsconfiguration recordModified files (4)
HttpDownloadOptionsparameterDesign
Related Issue
Closes #14
Verification