Skip to content

Commit 313d6fe

Browse files
committed
feat: 2.15.0
1 parent d8952cd commit 313d6fe

File tree

4 files changed

+8
-53
lines changed

4 files changed

+8
-53
lines changed

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.15.0-beta.1",
3+
"version": "2.15.0",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"types": "index.d.ts",
@@ -32,9 +32,9 @@
3232
"homepage": "https://github.com/tencentyun/cos-nodejs-sdk-v5#readme",
3333
"dependencies": {
3434
"conf": "^9.0.0",
35-
"cos-request": "^1.0.0",
3635
"fast-xml-parser": "4.2.5",
37-
"mime-types": "^2.1.24"
36+
"mime-types": "^2.1.24",
37+
"request": "^2.88.2"
3838
},
3939
"devDependencies": {
4040
"@types/node": "^14.14.20",
@@ -45,6 +45,6 @@
4545
"qcloud-cos-sts": "^3.1.1"
4646
},
4747
"engines": {
48-
"node": ">= 9"
48+
"node": ">= 6"
4949
}
5050
}

sdk/base.js

Lines changed: 3 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
var pkg = require('../package.json');
2-
var REQUEST = require('cos-request');
2+
var REQUEST = require('request');
33
var mime = require('mime-types');
44
var Stream = require('stream');
55
var util = require('./util');
@@ -3672,9 +3672,7 @@ function getAuthorizationAsync(params, callback) {
36723672
var headers = util.clone(params.Headers);
36733673
var headerHost = '';
36743674
util.each(headers, function (v, k) {
3675-
if (v === '') {
3676-
delete headers[k];
3677-
}
3675+
(v === '' || ['content-type', 'cache-control'].indexOf(k.toLowerCase()) > -1) && delete headers[k];
36783676
if (k.toLowerCase() === 'host') headerHost = v;
36793677
});
36803678

@@ -3993,47 +3991,6 @@ function submitRequest(params, callback) {
39933991
var Query = util.clone(params.qs);
39943992
params.action && (Query[params.action] = '');
39953993

3996-
var contentType;
3997-
var contentLength = 0;
3998-
util.each(params.headers, function (value, key) {
3999-
if (key.toLowerCase() === 'content-type') {
4000-
contentType = value;
4001-
}
4002-
if (key.toLowerCase() === 'content-length') {
4003-
contentLength = value;
4004-
}
4005-
});
4006-
4007-
var method = params.method.toLowerCase();
4008-
var body = params.body;
4009-
if (body) {
4010-
var isStringOrBuffer = typeof body === 'string' || Buffer.isBuffer(body);
4011-
if (!contentLength && isStringOrBuffer) {
4012-
// 传了请求体需补充 content-length
4013-
const buffer = Buffer.from(body, 'utf-8');
4014-
const contentLength = buffer.length;
4015-
params.headers['Content-Length'] = contentLength;
4016-
}
4017-
} else {
4018-
// 非 get 请求的空请求体需补充 content-length = 0
4019-
var noContentLengthMethods = ['get'].includes(method);
4020-
if (!noContentLengthMethods) {
4021-
params.headers['Content-Length'] = 0;
4022-
}
4023-
}
4024-
// 上传接口补充默认 content-type
4025-
if (contentType === undefined && body) {
4026-
var defaultContentType = 'application/octet-stream';
4027-
if (body.type) {
4028-
params.headers['Content-Type'] = body.type;
4029-
} else if (typeof body.pipe === 'function') {
4030-
var isReadStream = body && body.readable && body.path && body.mode;
4031-
params.headers['Content-Type'] = isReadStream ? (mime.lookup(body.path) || defaultContentType) : defaultContentType;
4032-
} else {
4033-
// params.headers['Content-Type'] = defaultContentType;
4034-
}
4035-
}
4036-
40373994
var SignHost =
40383995
params.SignHost || getSignHost.call(this, { Bucket: params.Bucket, Region: params.Region, Url: params.url });
40393996
var next = function (tryTimes) {
@@ -4086,7 +4043,7 @@ function submitRequest(params, callback) {
40864043
networkError,
40874044
});
40884045
params.SwitchHost = switchHost;
4089-
// 重试时增加请求体
4046+
// 重试时增加请求头
40904047
params.headers['x-cos-sdk-retry'] = true;
40914048
next(tryTimes + 1);
40924049
} else {

sdk/util.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,12 +56,10 @@ var obj2str = function (obj, lowerCaseKey) {
5656

5757
// 可以签入签名的headers
5858
var signHeaders = [
59-
'cache-control',
6059
'content-disposition',
6160
'content-encoding',
6261
'content-length',
6362
'content-md5',
64-
'content-type',
6563
'expect',
6664
'expires',
6765
'host',

test/test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
var fs = require('fs');
22
var path = require('path');
33
var COS = require('../index');
4-
var request = require('cos-request');
4+
var request = require('request');
55
var util = require('../demo/util');
66
var Stream = require('stream');
77

0 commit comments

Comments
 (0)