Wire up UserAgent from config to HTTP requests#1724
Conversation
…lient
- Set default UserAgent to "kubernetes-csharp/{version}" on KubernetesClientConfiguration
- Apply UserAgent header to HttpClient.DefaultRequestHeaders in CreateHttpClient
- Add tests for default and custom user-agent headers
Co-authored-by: tg123 <170430+tg123@users.noreply.github.com>
There was a problem hiding this comment.
Pull request overview
Adds a default HTTP User-Agent for the Kubernetes client and verifies the header behavior via integration-style tests against the mock API server.
Changes:
- Set a default
KubernetesClientConfiguration.UserAgentvalue tokubernetes-csharp/{GeneratedApiVersion.AssemblyVersion}. - Apply the configured
UserAgentto the underlyingHttpClientdefault request headers. - Add tests covering both default and custom
User-Agentbehavior.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| tests/KubernetesClient.Tests/AuthTests.cs | Adds tests asserting default and custom User-Agent headers are sent. |
| src/KubernetesClient/KubernetesClientConfiguration.cs | Introduces a default UserAgent value on the configuration object. |
| src/KubernetesClient/Kubernetes.ConfigInit.cs | Applies the configured UserAgent to HttpClient.DefaultRequestHeaders. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
@copilot fix build |
.NET SDK 10.0.201 (in the 200 band) requires MSBuild 18.0 which VS2022 does not provide. Pin to the 10.0.1xx feature band which is compatible with MSBuild 17.x. Co-authored-by: tg123 <170430+tg123@users.noreply.github.com>
The MSBuild build ( Fixed in |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: Copilot, tg123 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
KubernetesClientConfiguration.UserAgentexisted as a property but was never applied to outgoing HTTP requests.kubernetes-csharp/{GeneratedApiVersion.AssemblyVersion}so all requests identify the client out of the boxCreateHttpClient: SetsHttpClient.DefaultRequestHeadersviaTryAddWithoutValidationto tolerate version strings with metadata (e.g.+suffix)UserAgenton the config to any custom string, or null/empty to omitTests added for both default and custom user-agent propagation.