You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In my application I use a struct with an http.client
At all points where a request is made with this client, I would like to set my own custom user agent.
But here is the problem, I don't see a nice way to set this user agent as default in my http.client.
My first idea is to manipulate the transport and the associated http.RoundTripper:
However, The documentation for http.RoundTripper says: "RoundTrip should not modify the request, except for consuming and closing the Request's Body."
Alternatively, I can only see the possibility of manually setting the header in each request object created, but this can easily be forgotten and thus lead to inconsistencies.
It would be cool if you could specify default headers when creating the http.client, which would then be set automatically for each request.
The text was updated successfully, but these errors were encountered:
seankhliao
changed the title
proposal: affected/package: net/http: http.client default headers
proposal: net/http: set default headers in http.Client
Nov 21, 2023
I agree with #59266 on this subject, I put that on the RoundTripper implementation. Because there is no equivalent http.Clientinterface.
I don't think there is more value doing that in the client.
In my application I use a struct with an http.client
At all points where a request is made with this client, I would like to set my own custom user agent.
But here is the problem, I don't see a nice way to set this user agent as default in my http.client.
My first idea is to manipulate the transport and the associated http.RoundTripper:
However, The documentation for http.RoundTripper says: "RoundTrip should not modify the request, except for consuming and closing the Request's Body."
Alternatively, I can only see the possibility of manually setting the header in each request object created, but this can easily be forgotten and thus lead to inconsistencies.
It would be cool if you could specify default headers when creating the http.client, which would then be set automatically for each request.
The text was updated successfully, but these errors were encountered: