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

fix: upgrade urllib 3.17.1 and debug #1229

Open
wants to merge 41 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
01a87d2
test: upgrade urllib
Jul 18, 2023
ae926a6
Merge branch 'master' into csg/fix/master/50970931
Jul 18, 2023
fe332a2
test: upgrade urllib
Jul 18, 2023
fe214c5
chore: code format
Jul 19, 2023
91b1d69
fix: upgrade urllib transfer-encoding
Jul 19, 2023
bcda03e
test: upgrade urllib fix test case
Jul 19, 2023
5d8e5c3
test: upgrade urllib fix test case
Jul 19, 2023
13206e6
chore: remove autod
Jul 21, 2023
117f421
chore: upgrade snyk
Jul 21, 2023
5d80712
chore: remove lock.json
Jul 21, 2023
7c2e83f
test: test case
Jul 21, 2023
9b4c482
fix: test case
Jul 24, 2023
a00ba68
fix: test case
Jul 24, 2023
75e30e5
fix: test case
Jul 25, 2023
5b016e6
fix: test case
Jul 25, 2023
935c5f3
fix: test case
Jul 26, 2023
5d363b2
Merge branch 'master' into csg/fix/master/50970931
Aug 2, 2023
f58f579
chore: add package-lock.json
Aug 2, 2023
c230e9a
chore: remove package-lock.json
Aug 2, 2023
9619757
Merge branch 'master' into csg/fix/master/50970931
PeterRao Aug 2, 2023
28a5adc
test: add test timeout number
Aug 2, 2023
7f6230b
Merge branch 'csg/fix/master/50970931' of https://github.com/ali-sdk/…
Aug 2, 2023
f8bee46
test: edit test case
Aug 2, 2023
9387650
fix: remove request header content-type
Aug 3, 2023
a113221
chore: npm audit fix
Aug 3, 2023
dbe8e63
chore: test case
Aug 3, 2023
14fba2a
chore: npm audit fix
Aug 4, 2023
c09c813
chore: npm audit fix
Aug 4, 2023
154c409
chore: npm audit fix
Aug 4, 2023
be2d111
fix: upgrade urllib need node version > 13
Aug 4, 2023
71d1a8f
test: axios to urllib
Aug 4, 2023
da818ad
chore: update master_node_test.yml to node v18
Aug 4, 2023
6a90639
test: update test case
Aug 7, 2023
fe63c3e
test: update test case latin1 header encoding
Aug 16, 2023
0020473
test: update test case latin1 header encoding
Aug 16, 2023
148c7a3
test: update test case latin1 header encoding
Aug 16, 2023
4c86e4f
test: update test case latin1 header encoding
Aug 16, 2023
d50fe13
test: update test case latin1 header encoding
Aug 16, 2023
2175b99
test: update test case latin1 header encoding
Aug 16, 2023
12fbacd
fix: upgrade urllib to 2.41.0
Aug 17, 2023
d5b121a
Merge branch 'master' into csg/fix/master/50970931
Aug 18, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 2 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module.exports = {
],
'no-buffer-constructor': [2],
'comma-dangle': [0],
'import/prefer-default-export': [0]
'import/prefer-default-export': [0],
'no-void': 0
}
};
16 changes: 8 additions & 8 deletions .github/workflows/master_node_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
node browser-build.js > test/browser/build/aliyun-oss-sdk.min.js
node task/browser-test-build.js > test/browser/build/tests.js
npx karma start
node_10:
node_14:
environment: ali_oss_AK
runs-on: macos-latest

Expand All @@ -57,7 +57,7 @@ jobs:

strategy:
matrix:
node-version: [10.x]
node-version: [14.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -69,9 +69,9 @@ jobs:
- run: npm install
- run: npm run test

node_12:
node_16:
if: always()
needs: [node_10]
needs: [node_14]
environment: ali_oss_AK
runs-on: macos-latest

Expand All @@ -88,7 +88,7 @@ jobs:

strategy:
matrix:
node-version: [12.x]
node-version: [16.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand All @@ -100,9 +100,9 @@ jobs:
- run: npm install
- run: npm run test

node_14:
node_18:
if: always()
needs: [node_10, node_12]
needs: [node_14, node_16]
environment: ali_oss_AK
runs-on: macos-latest

Expand All @@ -119,7 +119,7 @@ jobs:

strategy:
matrix:
node-version: [14.x]
node-version: [18.x]
# See supported Node.js release schedule at https://nodejs.org/en/about/releases/

steps:
Expand Down
2 changes: 2 additions & 0 deletions lib/browser/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -242,6 +242,8 @@ async function request(params) {
const useStream = !!params.stream;
try {
result = await this.urllib.request(reqParams.url, reqParams.params);
// After upgrading urllib to v3, the res returned no longer has data, which is to be compatible with the old code
result.res.data = result.data;
this.debug(
'response %s %s, got %s, headers: %j',
params.method,
Expand Down
20 changes: 19 additions & 1 deletion lib/client.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
const debug = require('debug')('ali-oss');
const sendToWormhole = require('stream-wormhole');
const xml = require('xml2js');
// const fs = require('fs');
// const path = require('path');
const AgentKeepalive = require('agentkeepalive');
const HttpsAgentKeepalive = require('agentkeepalive').HttpsAgent;
const merge = require('merge-descriptors');
const platform = require('platform');
const utility = require('utility');
const urllib = require('urllib');
const ms = require('humanize-ms');
const pkg = require('../package.json');
const bowser = require('bowser');
const signUtils = require('./common/signUtils');
Expand Down Expand Up @@ -203,7 +206,23 @@ async function request(params) {
let result;
let reqErr;
try {
const { timeout } = reqParams.params;
if (typeof timeout === 'string') {
reqParams.params.timeout = ms(timeout); // Upgrading urllib to v3 no longer supports passing in strings
}
// const { writeStream } = reqParams.params;
// // check directory
// if (writeStream && writeStream.path) {
// const pname = writeStream.path;
// const dirname = path.dirname(pname);
// if (!fs.existsSync(dirname)) {
// // eslint-disable-next-line no-throw-literal
// throw { status: -1, message: `ENOENT: no such directory, open '${dirname}'` };
// }
// }
result = await this.urllib.request(reqParams.url, reqParams.params);
// After upgrading urllib to v3, the res returned no longer has data, which is to be compatible with the old code
result.res.data = result.data;
shungang marked this conversation as resolved.
Show resolved Hide resolved
debug('response %s %s, got %s, headers: %j', params.method, reqParams.url, result.status, result.headers);
} catch (err) {
reqErr = err;
Expand All @@ -215,7 +234,6 @@ async function request(params) {
} else if (reqErr) {
err = await this.requestError(reqErr);
}

if (err) {
if (params.customResponse && result && result.res) {
// consume the response stream
Expand Down
2 changes: 1 addition & 1 deletion lib/common/bucket/getBucketPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ proto.getBucketPolicy = async function getBucketPolicy(bucketName, options = {})
let policy = null;

if (result.res.status === 200) {
policy = JSON.parse(result.res.data.toString());
policy = JSON.parse(result.data.toString());
}

return {
Expand Down
1 change: 1 addition & 0 deletions lib/common/bucket/putBucketPolicy.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ proto.putBucketPolicy = async function putBucketPolicy(bucketName, policy, optio
throw new Error('policy is not Object');
}
const params = this._bucketRequestParams('PUT', bucketName, 'policy', options);
params.mime = 'json';
params.content = policy2Str(policy);
params.successStatuses = [200];
const result = await this.request(params);
Expand Down
1 change: 1 addition & 0 deletions lib/common/object/deleteMulti.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ proto.deleteMulti = async function deleteMulti(names, options = {}) {
if (options.versionId) {
options.subres.versionId = options.versionId;
}

const params = this._objectRequestParams('POST', '', options);
params.mime = 'xml';
params.content = paramXML;
Expand Down
176 changes: 91 additions & 85 deletions lib/common/utils/createRequest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
'use strict';

Object.defineProperty(exports, '__esModule', { value: true });
exports.createRequest = void 0;
const crypto = require('crypto');
const debug = require('debug')('ali-oss');
Expand All @@ -11,96 +12,101 @@ const { encoder } = require('./encoder');
const { isIP } = require('./isIP');
const { setRegion } = require('./setRegion');
const { getReqUrl } = require('../client/getReqUrl');

function getHeader(headers, name) {
return headers[name] || headers[name.toLowerCase()];
return headers[name] || headers[name.toLowerCase()];
}
function delHeader(headers, name) {
delete headers[name];
delete headers[name.toLowerCase()];
delete headers[name];
delete headers[name.toLowerCase()];
}
function createRequest(params) {
let date = new Date();
if (this.options.amendTimeSkewed) {
date = +new Date() + this.options.amendTimeSkewed;
let date = new Date();
if (this.options.amendTimeSkewed) {
date = +new Date() + this.options.amendTimeSkewed;
}
const headers = {
'x-oss-date': dateFormat(date, "UTC:ddd, dd mmm yyyy HH:MM:ss 'GMT'")
};
if (typeof window !== 'undefined') {
headers['x-oss-user-agent'] = this.userAgent;
}
if (this.userAgent.includes('nodejs')) {
headers['User-Agent'] = this.userAgent;
}
if (this.options.isRequestPay) {
Object.assign(headers, { 'x-oss-request-payer': 'requester' });
}
if (this.options.stsToken) {
headers['x-oss-security-token'] = this.options.stsToken;
}
copy(params.headers).to(headers);
if (!getHeader(headers, 'Content-Type')) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
} else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
const headers = {
'x-oss-date': dateFormat(date, "UTC:ddd, dd mmm yyyy HH:MM:ss 'GMT'")
};
if (typeof window !== 'undefined') {
headers['x-oss-user-agent'] = this.userAgent;
}
if (!getHeader(headers, 'Content-Type')) {
delHeader(headers, 'Content-Type');
}
if (params.content) {
if (!params.disabledMD5) {
if (!params.headers || !params.headers['Content-MD5']) {
headers['Content-MD5'] = crypto.createHash('md5').update(Buffer.from(params.content, 'utf8')).digest('base64');
} else {
headers['Content-MD5'] = params.headers['Content-MD5'];
}
}
if (this.userAgent.includes('nodejs')) {
headers['User-Agent'] = this.userAgent;
// if (!headers['Content-Length']) {
// headers['Content-Length'] = params.content.length;
// }
}
const { hasOwnProperty } = Object.prototype;
for (const k in headers) {
if (headers[k] && hasOwnProperty.call(headers, k)) {
headers[k] = encoder(String(headers[k]), this.options.headerEncoding);
}
if (this.options.isRequestPay) {
Object.assign(headers, { 'x-oss-request-payer': 'requester' });
}
if (this.options.stsToken) {
headers['x-oss-security-token'] = this.options.stsToken;
}
copy(params.headers).to(headers);
if (!getHeader(headers, 'Content-Type')) {
if (params.mime && params.mime.indexOf('/') > 0) {
headers['Content-Type'] = params.mime;
}
else {
headers['Content-Type'] = mime.getType(params.mime || path.extname(params.object || ''));
}
}
if (!getHeader(headers, 'Content-Type')) {
delHeader(headers, 'Content-Type');
}
if (params.content) {
if (!params.disabledMD5) {
if (!params.headers || !params.headers['Content-MD5']) {
headers['Content-MD5'] = crypto.createHash('md5').update(Buffer.from(params.content, 'utf8')).digest('base64');
}
else {
headers['Content-MD5'] = params.headers['Content-MD5'];
}
}
if (!headers['Content-Length']) {
headers['Content-Length'] = params.content.length;
}
}
const { hasOwnProperty } = Object.prototype;
for (const k in headers) {
if (headers[k] && hasOwnProperty.call(headers, k)) {
headers[k] = encoder(String(headers[k]), this.options.headerEncoding);
}
}
const authResource = this._getResource(params);
headers.authorization = this.authorization(params.method, authResource, params.subres, headers, this.options.headerEncoding);
// const url = this._getReqUrl(params);
if (isIP(this.options.endpoint.hostname)) {
const { region, internal, secure } = this.options;
const hostInfo = setRegion(region, internal, secure);
headers.host = `${params.bucket}.${hostInfo.host}`;
}
const url = getReqUrl.bind(this)(params);
debug('request %s %s, with headers %j, !!stream: %s', params.method, url, headers, !!params.stream);
const timeout = params.timeout || this.options.timeout;
const reqParams = {
method: params.method,
content: params.content,
stream: params.stream,
headers,
timeout,
writeStream: params.writeStream,
customResponse: params.customResponse,
ctx: params.ctx || this.ctx
};
if (this.agent) {
reqParams.agent = this.agent;
}
if (this.httpsAgent) {
reqParams.httpsAgent = this.httpsAgent;
}
reqParams.enableProxy = !!this.options.enableProxy;
reqParams.proxy = this.options.proxy ? this.options.proxy : null;
return {
url,
params: reqParams
};
}
const authResource = this._getResource(params);
headers.authorization = this.authorization(
params.method,
authResource,
params.subres,
headers,
this.options.headerEncoding
);
// const url = this._getReqUrl(params);
if (isIP(this.options.endpoint.hostname)) {
const { region, internal, secure } = this.options;
const hostInfo = setRegion(region, internal, secure);
headers.host = `${params.bucket}.${hostInfo.host}`;
}
const url = getReqUrl.bind(this)(params);
debug('request %s %s, with headers %j, !!stream: %s', params.method, url, headers, !!params.stream);
const timeout = params.timeout || this.options.timeout;
const reqParams = {
method: params.method,
content: params.content,
stream: params.stream,
headers,
timeout,
writeStream: params.writeStream,
customResponse: params.customResponse,
ctx: params.ctx || this.ctx
};
if (this.agent) {
reqParams.agent = this.agent;
}
if (this.httpsAgent) {
reqParams.httpsAgent = this.httpsAgent;
}
reqParams.enableProxy = !!this.options.enableProxy;
reqParams.proxy = this.options.proxy ? this.options.proxy : null;
return {
url,
params: reqParams
};
}
exports.createRequest = createRequest;
6 changes: 3 additions & 3 deletions lib/common/utils/createRequest.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,9 +75,9 @@ export function createRequest(this: any, params) {
headers['Content-MD5'] = params.headers['Content-MD5'];
}
}
if (!headers['Content-Length']) {
headers['Content-Length'] = params.content.length;
}
// if (!headers['Content-Length']) {
// headers['Content-Length'] = params.content.length;
// }
}

const { hasOwnProperty } = Object.prototype;
Expand Down