Skip to content

Commit 9fc3448

Browse files
committed
Add header to http/2 calls
1 parent 1554cbd commit 9fc3448

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
@@ -1079,10 +1079,13 @@ export class AuthorizedHttpClient extends HttpClient {
10791079
requestCopy.headers[authHeader] = `Bearer ${token}`;
10801080

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

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)