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

feat: callback support for callbackSNI #1291

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
86 changes: 56 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -460,8 +460,8 @@ try {
const putObjectResult = await store.put('your bucket name', 'your object name', {
headers: {
// The headers of this request
'header1': 'value1',
'header2': 'value2'
header1: 'value1',
header2: 'value2'
},
// The keys of the request headers that need to be calculated into the V4 signature. Please ensure that these additional headers are included in the request headers.
additionalHeaders: ['additional header1', 'additional header2']
Expand Down Expand Up @@ -1712,6 +1712,7 @@ parameters:
- [host] {String} The host header value for initiating callback requests.
- body {String} The value of the request body when a callback is initiated, for example, `key=${key}&etag=${etag}&my_var=${x:my_var}`.
- [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
- [customValue] {Object} Custom parameters are a map of key-values<br>
e.g.:
```js
Expand Down Expand Up @@ -1837,6 +1838,7 @@ parameters:
- [host] {String} The host header value for initiating callback requests.
- body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
- [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
- [customValue] {Object} Custom parameters are a map of key-values<br>
e.g.:
```js
Expand Down Expand Up @@ -2641,6 +2643,7 @@ parameters:
- [host] {String} set the host for callback
- body {String} set the body for callback
- [contentType] {String} set the type for body
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client
- [customValue] {Object} set the custom value for callback,eg. {var1: value1,var2:value2}
- [strictObjectNameValidation] {boolean} the flag of verifying object name strictly, default is true

Expand Down Expand Up @@ -2671,13 +2674,17 @@ const url = store.signatureUrl('ossdemo.txt', {
console.log(url);

// --------------------------------------------------
const url = store.signatureUrl('ossdemo.txt', {
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
}, false);
const url = store.signatureUrl(
'ossdemo.txt',
{
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
},
false
);
console.log(url);

// put operation
Expand Down Expand Up @@ -2723,6 +2730,7 @@ parameters:
- [host] {String} set the host for callback
- body {String} set the body for callback
- [contentType] {String} set the type for body
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client
- [customValue] {Object} set the custom value for callback,eg. {var1: value1,var2:value2}
- [strictObjectNameValidation] {boolean} the flag of verifying object name strictly, default is true

Expand Down Expand Up @@ -2750,13 +2758,17 @@ const url = await store.asyncSignatureUrl('ossdemo.txt', {
});
console.log(url);
// --------------------------------------------------
const url = await store.asyncSignatureUrl('ossdemo.txt', {
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
}, false);
const url = await store.asyncSignatureUrl(
'ossdemo.txt',
{
expires: 3600,
response: {
'content-type': 'text/custom',
'content-disposition': 'attachment'
}
},
false
);
console.log(url);
// put operation
```
Expand Down Expand Up @@ -2799,28 +2811,40 @@ example:
const getObjectUrl = await store.signatureUrlV4('GET', 60, undefined, 'your obejct name');
console.log(getObjectUrl);
// --------------------------------------------------
const getObjectUrl = await store.signatureUrlV4('GET', 60, {
headers: {
'Cache-Control': 'no-cache'
const getObjectUrl = await store.signatureUrlV4(
'GET',
60,
{
headers: {
'Cache-Control': 'no-cache'
},
queries: {
versionId: 'version ID of your object'
}
},
queries: {
versionId: 'version ID of your object'
}
}, 'your obejct name', ['Cache-Control']);
'your obejct name',
['Cache-Control']
);
console.log(getObjectUrl);

// -------------------------------------------------
// PutObject
const putObejctUrl = await store.signatureUrlV4('PUT', 60, undefined, 'your obejct name');
console.log(putObejctUrl);
// --------------------------------------------------
const putObejctUrl = await store.signatureUrlV4('PUT', 60, {
headers: {
'Content-Type': 'text/plain',
'Content-MD5': 'xxx',
'Content-Length': 1
}
}, 'your obejct name', ['Content-Length']);
const putObejctUrl = await store.signatureUrlV4(
'PUT',
60,
{
headers: {
'Content-Type': 'text/plain',
'Content-MD5': 'xxx',
'Content-Length': 1
}
},
'your obejct name',
['Content-Length']
);
console.log(putObejctUrl);
```

Expand Down Expand Up @@ -3233,6 +3257,7 @@ parameters:
- [host] {String} The host header value for initiating callback requests.
- body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
- [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
- [customValue] {Object} Custom parameters are a map of key-values<br>
e.g.:
```js
Expand Down Expand Up @@ -3318,6 +3343,7 @@ parameters:
- [host] {String} The host header value for initiating callback requests.
- body {String} The value of the request body when a callback is initiated, for example, key=${key}&etag=${etag}&my_var=${x:my_var}.
- [contentType] {String} The Content-Type of the callback requests initiatiated, It supports application/x-www-form-urlencoded and application/json, and the former is the default value.
- [callbackSNI] {Boolean} Specifies whether OSS sends Server Name Indication (SNI) to the origin address specified by callbackUrl when a callback request is initiated from the client.
- [customValue] {Object} Custom parameters are a map of key-values<br>
e.g.:
```js
Expand Down
1 change: 1 addition & 0 deletions lib/browser/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ const proto = exports;
* {String} options.callback.host The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Boolean} options.callback.callbackSNI Do you want to send the Server Name Indication
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
Expand Down
3 changes: 3 additions & 0 deletions lib/common/callback.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ exports.encodeCallback = function encodeCallback(reqParams, options) {
if (options.callback.contentType) {
json.callbackBodyType = options.callback.contentType;
}
if (options.callback.callbackSNI) {
json.callbackSNI = options.callback.callbackSNI;
}
const callback = Buffer.from(JSON.stringify(json)).toString('base64');
reqParams.headers['x-oss-callback'] = callback;

Expand Down
1 change: 1 addition & 0 deletions lib/common/multipart.js
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ proto.uploadPart = async function uploadPart(name, uploadId, partNo, file, start
* {String} options.callback.host The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Boolean} options.callback.callbackSNI Do you want to send the Server Name Indication
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
Expand Down
3 changes: 3 additions & 0 deletions lib/common/signUtils.js
Original file line number Diff line number Diff line change
Expand Up @@ -327,6 +327,9 @@ exports._signatureForURL = function _signatureForURL(accessKeySecret, options =
if (options.callback.contentType) {
json.callbackBodyType = options.callback.contentType;
}
if (options.callback.callbackSNI) {
json.callbackSNI = options.callback.callbackSNI;
}
subResource.callback = Buffer.from(JSON.stringify(json)).toString('base64');

if (options.callback.customValue) {
Expand Down
1 change: 1 addition & 0 deletions lib/managed-upload.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ const proto = exports;
* {String} options.callback.host The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Boolean} options.callback.callbackSNI Do you want to send the Server Name Indication
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
Expand Down
1 change: 1 addition & 0 deletions lib/object.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ proto.append = async function append(name, file, options) {
* {String} options.callback.host The host header value for initiating callback requests
* {String} options.callback.body The value of the request body when a callback is initiated
* {String} options.callback.contentType The Content-Type of the callback requests initiatiated
* {Boolean} options.callback.callbackSNI Do you want to send the Server Name Indication
* {Object} options.callback.customValue Custom parameters are a map of key-values, e.g:
* customValue = {
* key1: 'value1',
Expand Down
4 changes: 4 additions & 0 deletions test/browser/browser.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1803,6 +1803,7 @@ describe('browser', () => {
// /* eslint no-template-curly-in-string: [0] */
// body: 'bucket=${bucket}&object=${object}&var1=${x:var1}',
// contentType: 'application/x-www-form-urlencoded',
// callbackSNI: true,
// customValue: {
// var1: 'value1',
// var2: 'value2'
Expand All @@ -1825,6 +1826,7 @@ describe('browser', () => {
// host: 'oss-cn-hangzhou.aliyuncs.com',
// body: 'bucket=${bucket}&object=${object}&var1=${x:var1}',
// contentType: 'application/x-www-form-urlencoded',
// callbackSNI: true,
// customValue: {
// var1: 'value1',
// var2: 'value2'
Expand Down Expand Up @@ -1859,6 +1861,7 @@ describe('browser', () => {
// /* eslint no-template-curly-in-string: [0] */
// body: 'bucket=${bucket}&object=${object}&var1=${x:var1}',
// contentType: 'application/x-www-form-urlencoded',
// callbackSNI: true,
// customValue: {
// var1: 'value1',
// var2: 'value2'
Expand All @@ -1885,6 +1888,7 @@ describe('browser', () => {
// /* eslint no-template-curly-in-string: [0] */
// body: 'bucket=${bucket}&object=${object}&var1=${x:var1}',
// contentType: 'application/x-www-form-urlencoded',
// callbackSNI: true,
// customValue: {
// var1: 'value1',
// var2: 'value2'
Expand Down
Loading
Loading