-
Notifications
You must be signed in to change notification settings - Fork 7
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix: override auth header while retrying #896
Conversation
8a9e38c
to
d346322
Compare
@@ -215,7 +216,7 @@ export class BasicHttpClient { | |||
protected async request<ResponseType>(request: HttpRequest) { | |||
const mutatedRequest = await this.preRequest(request); | |||
const rawResponse = await this.rawRequest<ResponseType>(mutatedRequest); | |||
return this.postRequest(rawResponse, mutatedRequest); | |||
return this.postRequest(rawResponse, request, mutatedRequest); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need a way to differentiate between default headers and original headers in the request. Filtering out the default headers will not work because they can be overridden in the original request.
We need the mutated request to compare the authorization header used in the request, so maybe we can pass that instead of the whole request.
Codecov Report
@@ Coverage Diff @@
## master #896 +/- ##
==========================================
- Coverage 84.06% 79.52% -4.55%
==========================================
Files 70 105 +35
Lines 1952 3389 +1437
Branches 249 437 +188
==========================================
+ Hits 1641 2695 +1054
- Misses 301 692 +391
+ Partials 10 2 -8
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. As far as I can see, the SDK interface for the user would not change due to this PR.
@cemreyavuz Did the PR fix the problem? |
@BugGambit yes the problem is fixed with this version - also I have used it for the whole day and i didn't see any problem: 401s, retrys, etc. Everything looked fine 👍🏻 |
Latest change to this line caused a regression:
cognite-sdk-js/packages/core/src/httpClient/basicHttpClient.ts
Line 218 in 9797d78
Updated tokens are not used on retries for 401s now.
Because now we are passing
mutatedRequest
topostRequest
, not all the default headers are applied properly. For us, the important one is the authorization header. Here we keep using the old authorization header on retries of because of this ordering:cognite-sdk-js/packages/core/src/httpClient/basicHttpClient.ts
Lines 172 to 177 in 9797d78
I'm not sure if we should change this to other way - then we wouldn't be able to override default headers. So I went with adding another parameter to
postRequest
for keeping both the original request and the mutated version. Open to suggestions to clean it up.