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
This library currently always sets the Authorization header, even if request already has one.
Problem
To illustrate why that is a problem, lets say that I have a Client like this:
typeClientstruct {
httpClient*http.Client
}
that, for all but one endpoint, uses oauth2 library for setting Authorization token. If I want to provide my own, custom Authorization header value to that single endpoint, I have two choices:
This approach is impractical, because it may lead to inconsistent behavior. For example, if I had another RoundTripper that would further enhance outgoing requests, it's easy to miss that detail (for example Open Telemetry instrumentation).
Regardless of which would be better, this is just very awkward way of achieving it and I think also leads to potential inconsistencies, as the developer must ensure both clients have equivalent Transports (except for oauth2 obviously).
Proposed solution
In my view, this library should either preserve existing Authorization header out of the box (big, breaking change) or provide a way to instruct the library of the desired behavior, for example with context:
This library currently always sets the
Authorization
header, even if request already has one.Problem
To illustrate why that is a problem, lets say that I have a
Client
like this:that, for all but one endpoint, uses
oauth2
library for settingAuthorization
token. If I want to provide my own, customAuthorization
header value to that single endpoint, I have two choices:Configure new HTTP client:
This approach is impractical, because it may lead to inconsistent behavior. For example, if I had another
RoundTripper
that would further enhance outgoing requests, it's easy to miss that detail (for example Open Telemetry instrumentation).Pass another HTTP client to
Client
then use either like
or perhaps even stranger
Regardless of which would be better, this is just very awkward way of achieving it and I think also leads to potential inconsistencies, as the developer must ensure both clients have equivalent
Transport
s (except foroauth2
obviously).Proposed solution
In my view, this library should either preserve existing
Authorization
header out of the box (big, breaking change) or provide a way to instruct the library of the desired behavior, for example with context:in which case the library would simply not retrieve token and not set the header if one is already set.
The text was updated successfully, but these errors were encountered: