Skip to content

Commit a57315f

Browse files
authored
feat: signatureUrl support trafficLimit (#756)
1 parent 17c2984 commit a57315f

File tree

3 files changed

+42
-1
lines changed

3 files changed

+42
-1
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1817,6 +1817,7 @@ parameters:
18171817
- [Content-Type] {String} set the request content type
18181818
- [process] {String} image process params, will send with `x-oss-process`
18191819
e.g.: `{process: 'image/resize,w_200'}`
1820+
- [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`.
18201821
- [response] {Object} set the response headers for download
18211822
- [content-type] {String} set the response content type
18221823
- [content-disposition] {String} set the response content disposition

lib/common/signUtils.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,11 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r
112112
subResource[processKeyword] = options.process;
113113
}
114114

115+
if (options.trafficLimit) {
116+
const trafficLimitKey = 'x-oss-traffic-limit';
117+
subResource[trafficLimitKey] = options.trafficLimit;
118+
}
119+
115120
if (options.response) {
116121
Object.keys(options.response).forEach((k) => {
117122
const key = `response-${k.toLowerCase()}`;
@@ -128,7 +133,7 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r
128133
headers[key] = value;
129134
} else if (lowerKey.indexOf('content-type') === 0) {
130135
headers[key] = value;
131-
} else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method') {
136+
} else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method' && lowerKey !== 'trafficLimit') {
132137
subResource[lowerKey] = value;
133138
}
134139
});

test/node/object.test.js

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,6 +1038,41 @@ describe('test/object.test.js', () => {
10381038
// http://www.aliyun.com/darwin-v4.4.2/ali-sdk/oss/get-meta.js?OSSAccessKeyId=
10391039
assert.equal(url.indexOf('http://www.aliyun.com/'), 0);
10401040
});
1041+
1042+
it('should signature url with traffic limit', async () => {
1043+
const name = `${prefix}ali-sdk/oss/trafficLimit.js`;
1044+
let url, result;
1045+
const file_1mb = path.join(__dirname, '.tmp', 'bigfile-1mb.bin');
1046+
fs.writeFileSync(file_1mb, Buffer.alloc(1 * 1024 * 1024).fill('a\n'));
1047+
1048+
try {
1049+
url = store.signatureUrl(name, {
1050+
trafficLimit: 8 * 1024 * 100 * 4,
1051+
method: 'PUT'
1052+
})
1053+
1054+
result = await store.urllib.request(url, {
1055+
method: 'PUT',
1056+
stream: fs.createReadStream(file_1mb),
1057+
timeout: 600000,
1058+
});
1059+
assert.strictEqual(200, result.status)
1060+
} catch (error) {
1061+
assert(false, error.message)
1062+
}
1063+
1064+
try {
1065+
url = store.signatureUrl(name, {
1066+
trafficLimit: 8 * 1024 * 100 * 4,
1067+
})
1068+
result = await store.urllib.request(url, {
1069+
timeout: 600000,
1070+
});
1071+
assert.strictEqual(200, result.status)
1072+
} catch (error) {
1073+
assert(false, error.message)
1074+
}
1075+
});
10411076
});
10421077

10431078
describe('getStream()', () => {

0 commit comments

Comments
 (0)