Differentiate user-agent headers for library vs dnup HTTP calls #52740
+175
−4
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.
dotnet upmakes HTTP requests from two sources: theMicrosoft.Deployment.DotNet.Releaseslibrary (for release metadata) andDotnetArchiveDownloader(for archive downloads). Both were using the same or no custom user-agent, making usage metrics indistinguishable.Changes
New
ReleaseLibraryInitializer: Uses reflection to set custom user-agent on the library's internal staticHttpClientdotnetup-library/{version}dotnetup-dotnet-installer/{version}(unchanged)Initialization: Called early in
InstallerOrchestratorSingleton.Install()andSdkInstallCommand.Execute()before first library useError handling: Graceful degradation if reflection fails; logs to Debug output but doesn't break functionality
Implementation
The library's
Utils.s_httpClientis accessed via reflection since it's internal:Thread-safe singleton pattern with
_initializedflag prevents redundant reflection attempts.Original prompt
✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.