Skip to content

Commit 6670bcb

Browse files
authored
fix: gzip upload headers for symsrv (#113)
1 parent 47ade72 commit 6670bcb

File tree

4 files changed

+33
-3
lines changed

4 files changed

+33
-3
lines changed

src/common/client/s3-api-client/s3-api-client.spec.ts

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,29 @@ describe('S3ApiClient', () => {
4242
);
4343
});
4444

45+
it('should call fetch with additionalHeaders', async () => {
46+
const url = 'https://bugsplat.com';
47+
const name = '🐛.txt';
48+
const size = 1337;
49+
const file = { name, size, file: name } as any;
50+
const additionalHeaders = { 'content-encoding': 'gzip' };
51+
52+
await s3ApiClient.uploadFileToPresignedUrl(url, file, additionalHeaders);
53+
54+
expect((s3ApiClient as any)._fetch).toHaveBeenCalledWith(
55+
jasmine.anything(),
56+
jasmine.objectContaining({
57+
method: 'PUT',
58+
headers: {
59+
'content-type': 'application/octet-stream',
60+
'content-length': `${size}`,
61+
...additionalHeaders
62+
},
63+
body: file.file
64+
})
65+
);
66+
});
67+
4568
it('should return response', async () => {
4669
const url = 'https://bugsplat.com';
4770
const name = '🐛.txt';

src/common/client/s3-api-client/s3-api-client.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ export class S3ApiClient {
44

55
private _fetch = globalThis.fetch;
66

7-
async uploadFileToPresignedUrl(presignedUrl: string, file: UploadableFile): Promise<Response> {
7+
async uploadFileToPresignedUrl(presignedUrl: string, file: UploadableFile, additionalHeaders: HeadersInit = {}): Promise<Response> {
88
const response = await this._fetch(presignedUrl, {
99
method: 'PUT',
1010
headers: {
1111
'content-type': 'application/octet-stream',
12-
'content-length': `${file.size}`
12+
'content-length': `${file.size}`,
13+
...additionalHeaders
1314
},
1415
body: file.file as BodyInit,
1516
duplex: 'half'

src/symbols/symbols-api-client/symbols-api-client.spec.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,9 @@ describe('SymbolsApiClient', () => {
8484
url,
8585
jasmine.objectContaining({
8686
file: fakeUntouchedStream
87+
}),
88+
jasmine.objectContaining({
89+
'content-encoding': 'gzip'
8790
})
8891
);
8992
});

src/symbols/symbols-api-client/symbols-api-client.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,11 @@ export class SymbolsApiClient {
3737
version,
3838
file
3939
);
40+
const additionalHeaders = {
41+
'content-encoding': 'gzip'
42+
};
4043

41-
const uploadResponse = await this._s3ApiClient.uploadFileToPresignedUrl(presignedUrl, file);
44+
const uploadResponse = await this._s3ApiClient.uploadFileToPresignedUrl(presignedUrl, file, additionalHeaders);
4245

4346
await this.postUploadComplete(
4447
database,

0 commit comments

Comments
 (0)