Skip to content

Commit

Permalink
fix: copyObject set headers bug (#850)
Browse files Browse the repository at this point in the history
  • Loading branch information
weiyie authored Aug 24, 2020
1 parent 8f9c61b commit 2624cc3
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
11 changes: 10 additions & 1 deletion lib/common/object/copyObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,15 @@ const { checkBucketName: _checkBucketName } = require('../utils/checkBucketName'

const proto = exports;

const REPLACE_HEDERS = [
'content-type',
'content-encoding',
'content-language',
'content-disposition',
'cache-control',
'expires',
];

proto.copy = async function copy(name, sourceName, bucketName, options) {
if (typeof bucketName === 'object') {
options = bucketName; // 兼容旧版本,旧版本第三个参数为options
Expand All @@ -12,7 +21,7 @@ proto.copy = async function copy(name, sourceName, bucketName, options) {
Object.keys(options.headers).forEach((key) => {
options.headers[`x-oss-copy-source-${key.toLowerCase()}`] = options.headers[key];
});
if (options.meta) {
if (options.meta || Object.keys(options.headers).find(_ => REPLACE_HEDERS.includes(_.toLowerCase()))) {
options.headers['x-oss-metadata-directive'] = 'REPLACE';
}
this._convertMetaToHeaders(options.meta, options.headers);
Expand Down
13 changes: 13 additions & 0 deletions test/node/object.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1364,6 +1364,19 @@ describe('test/object.test.js', () => {
assert.equal(info.status, 200);
});

it('should copy object from same bucket and set content-disposition', async () => {
const originname = `${prefix}ali-sdk/oss/copy-content-disposition.js`;
const disposition = 'attachment; filename=test';
const result = await store.copy(originname, name, {
headers: {
'Content-Disposition': disposition
},
});
assert.strictEqual(result.res.status, 200);
const { res } = await store.get(originname);
assert.strictEqual(res.headers['content-disposition'], disposition);
});

it('should copy object from other bucket, sourceBucket in copySource', async () => {
const copySource = `/${otherBucket}/${otherBucketObject}`;
const copyTarget = `${prefix}ali-sdk/oss/copy-target.js`;
Expand Down

0 comments on commit 2624cc3

Please sign in to comment.