Skip to content

Commit 11f816e

Browse files
committed
Add header to http/2 calls
1 parent e886df8 commit 11f816e

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

src/app/credential-internal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ export class ApplicationDefaultCredential implements Credential {
7272

7373
public getQuotaProjectId(): string | undefined {
7474
if (!this.quotaProjectId) {
75-
this.quotaProjectId = this.authClient.quotaProjectId;
75+
this.quotaProjectId = this.authClient?.quotaProjectId;
7676
}
7777
return this.quotaProjectId;
7878
}

src/utils/api-request.ts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1078,10 +1078,13 @@ export class AuthorizedHttpClient extends HttpClient {
10781078
requestCopy.headers[authHeader] = `Bearer ${token}`;
10791079

10801080
let quotaProjectId: string | undefined;
1081-
if (this.app.options.credential instanceof ApplicationDefaultCredential){
1081+
if (process.env.GOOGLE_CLOUD_QUOTA_PROJECT) {
1082+
quotaProjectId = process.env.GOOGLE_CLOUD_QUOTA_PROJECT;
1083+
}
1084+
else if (this.app.options.credential instanceof ApplicationDefaultCredential){
10821085
quotaProjectId = this.app.options.credential.getQuotaProjectId();
10831086
}
1084-
quotaProjectId = process.env.GOOGLE_CLOUD_QUOTA_PROJECT || undefined;
1087+
10851088
if (!requestCopy.headers['x-goog-user-project'] && validator.isNonEmptyString(quotaProjectId)) {
10861089
requestCopy.headers['x-goog-user-project'] = quotaProjectId;
10871090
}

test/unit/utils/api-request.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2569,6 +2569,9 @@ describe('AuthorizedHttpClient', () => {
25692569
afterEach(() => {
25702570
transportSpy!.restore();
25712571
transportSpy = null;
2572+
if (process.env.GOOGLE_CLOUD_QUOTA_PROJECT) {
2573+
delete process.env.GOOGLE_CLOUD_QUOTA_PROJECT;
2574+
}
25722575
return mockAppWithAgent.delete();
25732576
});
25742577

0 commit comments

Comments
 (0)