Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding gzip headers to reduce payload sizes and enable compression #591

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading