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: putBucketCORS support responseVary config #1143

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
19 changes: 17 additions & 2 deletions lib/bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,19 @@ proto.deleteBucketLogging = async function deleteBucketLogging(name, options) {
};
};

proto.putBucketCORS = async function putBucketCORS(name, rules, options) {
proto.putBucketCORS = async function putBucketCORS(name, rulesOrConfiguration, options) {
_checkBucketName(name);
rules = rules || [];

let rules = [];
let responseVary;

if (isArray(rulesOrConfiguration)) {
rules = rulesOrConfiguration || [];
} else {
rules = rulesOrConfiguration.rules || [];
responseVary = rulesOrConfiguration.responseVary;
}

assert(rules.length, 'rules is required');
rules.forEach((rule) => {
assert(rule.allowedOrigin, 'allowedOrigin is required');
Expand Down Expand Up @@ -238,6 +248,11 @@ proto.putBucketCORS = async function putBucketCORS(name, rules, options) {
}
xml += '</CORSRule>';
}

if (typeof responseVary === 'boolean') {
xml += `<ResponseVary>${responseVary.toString()}</ResponseVary>`;
}

xml += '</CORSConfiguration>';
params.content = xml;
params.mime = 'xml';
Expand Down