Skip to content

Commit 44c97ab

Browse files
committed
支持自定义 Protocol
1 parent 3324941 commit 44c97ab

File tree

3 files changed

+9
-3
lines changed

3 files changed

+9
-3
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cos-nodejs-sdk-v5",
3-
"version": "2.3.3",
3+
"version": "2.3.4",
44
"description": "cos nodejs sdk v5",
55
"main": "index.js",
66
"scripts": {

sdk/base.js

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ function getService(params, callback) {
1818
callback = params;
1919
params = {};
2020
}
21-
var protocol = util.isBrowser && location && location.protocol === 'https:' ? 'https:' : 'http:';
21+
var protocol = this.options.Protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
2222
var domain = this.options.ServiceDomain;
2323
var appId = params.AppId || this.options.appId;
2424
if (domain) {
@@ -150,6 +150,7 @@ function putBucket(params, callback) {
150150
return callback(err);
151151
}
152152
var url = getUrl({
153+
protocol: self.options.Protocol,
153154
domain: self.options.Domain,
154155
bucket: params.Bucket,
155156
region: params.Region,
@@ -1105,6 +1106,7 @@ function putObject(params, callback) {
11051106
}
11061107
if (data && data.headers && data.headers['etag']) {
11071108
var url = getUrl({
1109+
protocol: self.options.Protocol,
11081110
domain: self.options.Domain,
11091111
bucket: params.Bucket,
11101112
region: params.Region,
@@ -1571,6 +1573,7 @@ function multipartComplete(params, callback) {
15711573
return callback(err);
15721574
}
15731575
var url = getUrl({
1576+
protocol: self.options.Protocol,
15741577
domain: self.options.Domain,
15751578
bucket: params.Bucket,
15761579
region: params.Region,
@@ -1761,6 +1764,7 @@ function getAuth(params) {
17611764
function getObjectUrl(params, callback) {
17621765
var self = this;
17631766
var url = getUrl({
1767+
protocol: self.options.Protocol,
17641768
domain: self.options.Domain,
17651769
bucket: params.Bucket,
17661770
region: params.Region,
@@ -1847,7 +1851,7 @@ function getUrl(params) {
18471851
var region = params.region;
18481852
var object = params.object;
18491853
var action = params.action;
1850-
var protocol = util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:';
1854+
var protocol = params.protocol || (util.isBrowser && location.protocol === 'http:' ? 'http:' : 'https:');
18511855
if (!domain) {
18521856
if (['cn-south', 'cn-south-2', 'cn-north', 'cn-east', 'cn-southwest', 'sg'].indexOf(region) > -1) {
18531857
domain = '{{Bucket}}-{{AppId}}.{{Region}}.myqcloud.com';
@@ -1972,6 +1976,7 @@ function _submitRequest(params, callback) {
19721976

19731977
var opt = {
19741978
url: url || getUrl({
1979+
protocol: self.options.Protocol,
19751980
domain: self.options.Domain,
19761981
bucket: bucket,
19771982
region: region,

sdk/cos.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ var defaultOptions = {
1919
Domain: '',
2020
ServiceDomain: '',
2121
SliceSize: 1024 * 1024 * 20,
22+
Protocol: '',
2223
Proxy: '',
2324
};
2425

0 commit comments

Comments
 (0)