mirror of
https://github.com/azaion/satellite-provider.git
synced 2026-06-22 05:21:14 +00:00
[AZ-374] Refactor C21: named GoogleMapsTiles HttpClient in DI
- Register IHttpClientFactory named client "GoogleMapsTiles" inside AddTileDownloader() with User-Agent and 100s timeout (preserves HttpClient's implicit default). - Resolve the same named client from all three CreateClient() call sites in GoogleMapsDownloaderV2 (session token, single-tile, batch-tile retry lambda) and drop the duplicated per-call UserAgent.ParseAdd setup. - Expose USER_AGENT, the client name, and the timeout as internal consts on GoogleMapsDownloaderV2 so the extension and the downloader share one source of truth. - Add AC test that builds the DI container, resolves the named client, and asserts both the User-Agent header and the timeout. - Archive AZ-374 task file: todo/ -> done/. 175 unit + 5 smoke pass. Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -1,62 +0,0 @@
|
||||
# Refactor: register typed HttpClient for Google Maps in DI
|
||||
|
||||
**Task**: AZ-374_refactor_typed_httpclient_googlemaps
|
||||
**Name**: Named HttpClient for GoogleMapsDownloaderV2
|
||||
**Description**: Register a named `HttpClient` ("GoogleMapsTiles") with default headers + timeout, and have `GoogleMapsDownloaderV2` resolve it via `IHttpClientFactory.CreateClient("GoogleMapsTiles")` everywhere.
|
||||
**Complexity**: 2 points
|
||||
**Dependencies**: None
|
||||
**Component**: Api + Services.TileDownloader
|
||||
**Tracker**: AZ-374
|
||||
**Epic**: AZ-350
|
||||
|
||||
## Problem
|
||||
|
||||
`SatelliteProvider.Services.TileDownloader/GoogleMapsDownloaderV2.cs:51, 107, 369` calls `_httpClientFactory.CreateClient()` in three different code paths (session-token fetch, single-tile download, batch-tile download retry lambda) and sets the `User-Agent` header per call. The factory pools `HttpMessageHandler`s correctly, but the per-call header setup is duplicated and error-prone.
|
||||
|
||||
## Outcome
|
||||
|
||||
- Single named-client registration in `Program.cs`.
|
||||
- All three downloader paths resolve `CreateClient("GoogleMapsTiles")`.
|
||||
- Same outbound HTTP behavior.
|
||||
- 37 unit + 5 smoke tests stay green.
|
||||
|
||||
## Scope
|
||||
|
||||
### Included
|
||||
- Add `services.AddHttpClient("GoogleMapsTiles", c => { c.DefaultRequestHeaders.UserAgent.ParseAdd(USER_AGENT); c.Timeout = TimeSpan.FromSeconds(<existing default>); });` in `Program.cs`.
|
||||
- Replace three `CreateClient()` calls with `CreateClient("GoogleMapsTiles")`.
|
||||
- Remove the per-call `UserAgent` setup.
|
||||
|
||||
### Excluded
|
||||
- Migrating to a typed `HttpClient` subclass (deferred).
|
||||
- Adding Polly or retry policy at the factory level (existing manual retry stays).
|
||||
|
||||
## Acceptance Criteria
|
||||
|
||||
**AC-1: Single registration**
|
||||
Given the post-refactor `Program.cs`
|
||||
When inspected
|
||||
Then a single `AddHttpClient("GoogleMapsTiles", ...)` registration exists.
|
||||
|
||||
**AC-2: Downloader uses the named client**
|
||||
Given the post-refactor downloader
|
||||
When grepped for `CreateClient(`
|
||||
Then all matches use the `"GoogleMapsTiles"` name.
|
||||
|
||||
**AC-3: Tests stay green**
|
||||
Given the post-refactor build
|
||||
When `scripts/run-tests.sh --smoke` runs
|
||||
Then all 37 unit + 5 smoke scenarios pass.
|
||||
|
||||
## Constraints
|
||||
|
||||
- Same outbound `User-Agent` header text.
|
||||
- Same timeout (use the existing implicit default until C18 wires this to config).
|
||||
|
||||
## Risks & Mitigation
|
||||
|
||||
**Risk 1: timeout default surprises a slow path**
|
||||
- *Risk*: setting an explicit timeout may cut off a slow Google Maps response that previously hung indefinitely.
|
||||
- *Mitigation*: pick a generous default (e.g., 60 s) matching observed worst case; tune via C18.
|
||||
|
||||
Full change entry: `_docs/04_refactoring/03-code-quality-refactoring/list-of-changes.md` (C21).
|
||||
Reference in New Issue
Block a user