Skip to content

Commit f164923

Browse files
committed
fix: perform immutable updates on customRequestOptions to avoid mutating shared header objects
1 parent 778c5b0 commit f164923

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

handwritten/storage/src/resumable-upload.ts

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -818,7 +818,11 @@ export class Upload extends Writable {
818818
if (hasValidUserToken) {
819819
this.currentInvocationId.uri = userTokenValue as string;
820820
} else if (userTokenKey && this.customRequestOptions?.headers) {
821-
delete this.customRequestOptions.headers[userTokenKey];
821+
this.customRequestOptions = {
822+
...this.customRequestOptions,
823+
headers: { ...this.customRequestOptions.headers },
824+
};
825+
delete this.customRequestOptions.headers![userTokenKey];
822826
}
823827

824828
let googAPIClient = `${getRuntimeTrackingString()} gccl/${
@@ -1022,7 +1026,11 @@ export class Upload extends Writable {
10221026
if (hasValidUserToken) {
10231027
this.currentInvocationId.chunk = userTokenValue as string;
10241028
} else if (userTokenKey && this.customRequestOptions?.headers) {
1025-
delete this.customRequestOptions.headers[userTokenKey];
1029+
this.customRequestOptions = {
1030+
...this.customRequestOptions,
1031+
headers: { ...this.customRequestOptions.headers },
1032+
};
1033+
delete this.customRequestOptions.headers![userTokenKey];
10261034
}
10271035

10281036
let googAPIClient = `${getRuntimeTrackingString()} gccl/${
@@ -1251,7 +1259,11 @@ export class Upload extends Writable {
12511259
if (hasValidUserToken) {
12521260
this.currentInvocationId.checkUploadStatus = userTokenValue as string;
12531261
} else if (userTokenKey && this.customRequestOptions?.headers) {
1254-
delete this.customRequestOptions.headers[userTokenKey];
1262+
this.customRequestOptions = {
1263+
...this.customRequestOptions,
1264+
headers: { ...this.customRequestOptions.headers },
1265+
};
1266+
delete this.customRequestOptions.headers![userTokenKey];
12551267
}
12561268

12571269
let googAPIClient = `${getRuntimeTrackingString()} gccl/${

0 commit comments

Comments
 (0)