[BUG] Cannot set `User-Agent` header in track2 SDK
See original GitHub issueLibrary name and version
Azure.ResourceManager
Describe the bug
Description
The following code snippet (copied from https://github.com/Azure/azure-sdk-for-net/blob/main/sdk/core/Azure.Core/samples/Pipeline.md#implementing-a-synchronous-policy) doesn’t work.
public class CustomRequestPolicy : HttpPipelineSynchronousPolicy
{
public override void OnSendingRequest(HttpMessage message)
{
message.Request.Headers.Add("User-Agent", "abc");
}
}
The root cause is that we have an internal override https://github.com/Azure/azure-sdk-for-net/blob/d269eede20a23edec101477601a2b90bee54e690/sdk/resourcemanager/Azure.ResourceManager/src/Internal/MgmtTelemetryPolicy.cs#L21
So external users cannot simply set User-Agent
by Headers.Add()
or Headers.Set()
.
Expected behavior
The following code snippet should add a User-Agent
header value.
public class CustomRequestPolicy : HttpPipelineSynchronousPolicy
{
public override void OnSendingRequest(HttpMessage message)
{
message.Request.Headers.Add("User-Agent", "abc");
}
}
Actual behavior
User-Agent
header value cannot be modified through Headers.Add()
or Headers.Set()
.
Reproduction Steps
Try the code snippet at the beginning.
Environment
No response
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:7 (6 by maintainers)
Top Results From Across the Web
Sending a custom User-Agent string along with my ...
1 Answer. After some testing, Chrome does indeed have a bug with the User-Agent header. This is most likely due to the fact...
Read more >KinesisVideoArchivedMediaClient
KinesisVideoArchivedMediaClient Operations · x-amz-ErrorType HTTP header – contains a more specific error type in addition to what the HTTP status code provides.
Read more >User-Agent header disallowed via 'Access-Control-Allow- ...
I've started making a web app that interacts with the iNaturalist API directly through javascript in the browser, and I've been trying to...
Read more >Am I breaking the API rules if I don't set the User-Agent ...
I am developing a HTML + Javascript application that uses the reddit API. The app obtains the OAuth access token using the implicit...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we need to make a decision: shall we allow users to modify
User-Agent
? We could change the logic inMgmtTelemetryPolicy.cs
to add (v.s. set) the value passed byUserAgentOverride
, which will make sure theUser-Agent
set by each SDK will be passed to back-end.I checked with Powershell team. And it looks like the backend analytics can support long strings. So appending custom
user-agent
headers seems the best option, e.g. the final header value will look like: