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

_signatureForURL support query #756

Merged
merged 1 commit into from
Mar 25, 2020
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1802,6 +1802,7 @@ parameters:
- [Content-Type] {String} set the request content type
- [process] {String} image process params, will send with `x-oss-process`
e.g.: `{process: 'image/resize,w_200'}`
- [trafficLimit] {Number} traffic limit, range: `819200`~`838860800`.
- [response] {Object} set the response headers for download
- [content-type] {String} set the response content type
- [content-disposition] {String} set the response content disposition
Expand Down
7 changes: 6 additions & 1 deletion lib/common/signUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,11 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r
subResource[processKeyword] = options.process;
}

if (options.trafficLimit) {
const trafficLimitKey = 'x-oss-traffic-limit';
subResource[trafficLimitKey] = options.trafficLimit;
}

if (options.response) {
Object.keys(options.response).forEach((k) => {
const key = `response-${k.toLowerCase()}`;
Expand All @@ -128,7 +133,7 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options, r
headers[key] = value;
} else if (lowerKey.indexOf('content-type') === 0) {
headers[key] = value;
} else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method') {
} else if (lowerKey !== 'expires' && lowerKey !== 'response' && lowerKey !== 'process' && lowerKey !== 'method' && lowerKey !== 'trafficLimit') {
subResource[lowerKey] = value;
}
});
Expand Down
35 changes: 35 additions & 0 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1038,6 +1038,41 @@ describe('test/object.test.js', () => {
// http://www.aliyun.com/darwin-v4.4.2/ali-sdk/oss/get-meta.js?OSSAccessKeyId=
assert.equal(url.indexOf('http://www.aliyun.com/'), 0);
});

it('should signature url with traffic limit', async () => {
const name = `${prefix}ali-sdk/oss/trafficLimit.js`;
let url, result;
const file_1mb = path.join(__dirname, '.tmp', 'bigfile-1mb.bin');
fs.writeFileSync(file_1mb, Buffer.alloc(1 * 1024 * 1024).fill('a\n'));

try {
url = store.signatureUrl(name, {
trafficLimit: 8 * 1024 * 100 * 4,
method: 'PUT'
})

result = await store.urllib.request(url, {
method: 'PUT',
stream: fs.createReadStream(file_1mb),
timeout: 600000,
});
assert.strictEqual(200, result.status)
} catch (error) {
assert(false, error.message)
}

try {
url = store.signatureUrl(name, {
trafficLimit: 8 * 1024 * 100 * 4,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个参数是 String 还是 Number

})
result = await store.urllib.request(url, {
timeout: 600000,
});
assert.strictEqual(200, result.status)
} catch (error) {
assert(false, error.message)
}
});
});

describe('getStream()', () => {
Expand Down