Skip to content

Commit

Permalink
Adding gzip headers to reduce payload sizes and enable compression (#591
Browse files Browse the repository at this point in the history
)

* Adding gzip headers to reduce payload sizes and enable compression

* fix tests

* fix test

* fix more tests
  • Loading branch information
johnjjung authored Oct 18, 2024
1 parent 27518a2 commit 214cb58
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
1 change: 1 addition & 0 deletions src/apiClient.ts
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@ export default class APIClient {
objKeysToSnakeCase(optionParams.body, ['metadata']) // metadata should remain as is
);
requestOptions.headers['Content-Type'] = 'application/json';
requestOptions.headers['Accept-Encoding'] = 'gzip';
}

if (optionParams.form) {
Expand Down
13 changes: 12 additions & 1 deletion tests/apiClient.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ describe('APIClient', () => {
timeout: 30,
headers: {
'X-SDK-Test-Header': 'This is a test',
'Accept-Encoding': 'gzip',
},
});

Expand All @@ -28,6 +29,7 @@ describe('APIClient', () => {
expect(client.timeout).toBe(30000);
expect(client.headers).toEqual({
'X-SDK-Test-Header': 'This is a test',
'Accept-Encoding': 'gzip',
});
});
});
Expand All @@ -49,7 +51,10 @@ describe('APIClient', () => {
const options = client.requestOptions({
path: '/test',
method: 'GET',
headers: { 'X-SDK-Test-Header': 'This is a test' },
headers: {
'X-SDK-Test-Header': 'This is a test',
'Accept-Encoding': 'gzip',
},
queryParams: { param: 'value' },
body: { id: 'abc123' },
overrides: { apiUri: 'https://test.api.nylas.com' },
Expand All @@ -60,6 +65,7 @@ describe('APIClient', () => {
Accept: 'application/json',
Authorization: 'Bearer testApiKey',
'Content-Type': 'application/json',
'Accept-Encoding': 'gzip',
'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
'X-SDK-Test-Header': 'This is a test',
});
Expand All @@ -73,12 +79,16 @@ describe('APIClient', () => {
const options = client.requestOptions({
path: '/test',
method: 'POST',
headers: {
'Accept-Encoding': 'gzip',
},
});

expect(options.method).toBe('POST');
expect(options.headers).toEqual({
Accept: 'application/json',
Authorization: 'Bearer testApiKey',
'Accept-Encoding': 'gzip',
'User-Agent': `Nylas Node SDK v${SDK_VERSION}`,
});
expect(options.url).toEqual(new URL('https://api.us.nylas.com/test'));
Expand Down Expand Up @@ -167,6 +177,7 @@ describe('APIClient', () => {
Accept: ['application/json'],
Authorization: ['Bearer testApiKey'],
'Content-Type': ['application/json'],
'Accept-Encoding': ['gzip'],
'User-Agent': [`Nylas Node SDK v${SDK_VERSION}`],
'X-SDK-Test-Header': ['This is a test'],
'global-header': ['global-value'],
Expand Down

0 comments on commit 214cb58

Please sign in to comment.