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

SNOW-917244: Remove axios content encoding workaround #653

Merged
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
27 changes: 3 additions & 24 deletions lib/http/base.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,8 @@ HttpClient.prototype.request = function (options)
timeout: timeout,
requestOCSP: true,
rejectUnauthorized: true,
// axios does not know how to decode response with content-encoding GZIP (it should be gzip)
// that we receive from GCS, so let's get response as arraybuffer and unzip it outside axios
// issue in axios about case insensitive content-encoding is marked as won't fix: https://github.com/axios/axios/issues/4280
// for all other responses we manually parse jsons or other structures from the server so they need to be text
// TODO SNOW-917244 we can get rid of this logic when axios > 1.5.0 will be release as it should contain fix https://github.com/axios/axios/issues/5890
responseType: options.url.includes('storage.googleapis.com') ? 'arraybuffer' : 'text',
// we manually parse jsons or other structures from the server so they need to be text
responseType: 'text',
};

let mock;
Expand All @@ -106,24 +102,7 @@ HttpClient.prototype.request = function (options)

request = axios.request(requestOptions).then(response => {
if (Util.isFunction(options.callback)) {
if (options.url.includes('storage.googleapis.com')) {
// we request that GCS returns body as arraybuffer, not text
// when it is GZIPped then we have to unzip it
// otherwise we should convert arraybuffer to string
// TODO SNOW-917244 we can get rid of this logic when axios > 1.5.0 will be release as it should contain fix https://github.com/axios/axios/issues/5890
try {
if (response.headers['content-encoding'] === 'GZIP') {
const unzippedData = zlib.gunzipSync(response.data).toString('utf-8');
return options.callback(null, normalizeResponse(response), unzippedData);
} else {
return options.callback(null, normalizeResponse(response), new TextDecoder('utf-8').decode(response.data));
}
} catch (e) {
return options.callback(e, null, null);
}
} else {
return options.callback(null, normalizeResponse(response), response.data);
}
return options.callback(null, normalizeResponse(response), response.data);
} else {
Logger.getInstance().trace(`Callback function was not provided for the call to ${options.url}`);
return null;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"agent-base": "^6.0.2",
"asn1.js-rfc2560": "^5.0.0",
"asn1.js-rfc5280": "^3.0.0",
"axios": "^1.5.0",
"axios": "^1.5.1",
"big-integer": "^1.6.43",
"bignumber.js": "^2.4.0",
"binascii": "0.0.2",
Expand Down
Loading