Skip to content
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
1 change: 1 addition & 0 deletions lib/api/apiUtils/object/createAndStoreObject.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,7 @@ function createAndStoreObject(bucketName, bucketMD, objectKey, objMD, authInfo,
metadataStoreParams.cacheControl = request.headers['cache-control'];
metadataStoreParams.contentDisposition =
request.headers['content-disposition'];
metadataStoreParams.contentLanguage = request.headers['content-language'];
metadataStoreParams.contentEncoding =
removeFromCommaSeparatedList(request.headers['content-encoding'], constants.awsChunkedContentEncoding);
metadataStoreParams.expires = request.headers.expires;
Expand Down
1 change: 1 addition & 0 deletions lib/api/completeMultipartUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -343,6 +343,7 @@ function completeMultipartUpload(authInfo, request, log, callback) {
cacheControl: storedMetadata['cache-control'],
contentDisposition: storedMetadata['content-disposition'],
contentEncoding: storedMetadata['content-encoding'],
contentLanguage: storedMetadata['content-language'],
expires: storedMetadata.expires,
contentMD5: aggregateETag,
size: calculatedSize,
Expand Down
1 change: 1 addition & 0 deletions lib/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ function _prepMetadata(
// aws-chunked removal, such as 'gzip,'
contentEncoding: removeFromCommaSeparatedList(
headersToStoreSource['content-encoding'], constants.awsChunkedContentEncoding, ''),
contentLanguage: headersToStoreSource['content-language'],
dataStoreName: destLocationConstraintName,
expires: headersToStoreSource.expires,
overrideMetadata,
Expand Down
3 changes: 3 additions & 0 deletions lib/services.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const services = {
cacheControl,
contentDisposition,
contentEncoding,
contentLanguage,
expires,
multipart,
headers,
Expand Down Expand Up @@ -155,6 +156,7 @@ const services = {
.setCacheControl(cacheControl)
.setContentDisposition(contentDisposition)
.setContentEncoding(contentEncoding)
.setContentLanguage(contentLanguage)
.setExpires(expires)
.setContentLength(size)
.setContentType(contentType)
Expand Down Expand Up @@ -575,6 +577,7 @@ const services = {
multipartObjectMD['content-disposition'] = params.headers['content-disposition'];
multipartObjectMD['content-encoding'] = removeFromCommaSeparatedList(
params.headers['content-encoding'], constants.awsChunkedContentEncoding);
multipartObjectMD['content-language'] = params.headers['content-language'];
multipartObjectMD['content-type'] = params.headers['content-type'];
multipartObjectMD.expires = params.headers.expires;
multipartObjectMD['x-amz-storage-class'] = params.storageClass; // TODO: removed CLDSRV-639
Expand Down
3 changes: 3 additions & 0 deletions lib/utilities/collectResponseHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,9 @@ function collectResponseHeaders(objectMD, corsHeaders, versioningCfg,
if (contentEncoding) {
responseMetaHeaders['Content-Encoding'] = contentEncoding;
}
if (objectMD['content-language']) {
responseMetaHeaders['Content-Language'] = objectMD['content-language'];
}
if (objectMD.expires) {
responseMetaHeaders.Expires = objectMD.expires;
}
Expand Down
13 changes: 12 additions & 1 deletion tests/functional/aws-node-sdk/test/object/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ describe('GET object', () => {
});

describe('Additional headers: [Cache-Control, Content-Disposition, ' +
'Content-Encoding, Expires, Accept-Ranges]', () => {
'Content-Encoding, Content-Language, Expires, Accept-Ranges]', () => {
describe('if specified in put object request', () => {
before(async () => {
const params = {
Expand All @@ -254,6 +254,7 @@ describe('GET object', () => {
CacheControl: cacheControl,
ContentDisposition: contentDisposition,
ContentEncoding: contentEncoding,
ContentLanguage: contentLanguage,
ContentType: contentType,
Expires: expires,
};
Expand All @@ -269,13 +270,23 @@ describe('GET object', () => {
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding,
'gzip');
assert.strictEqual(res.ContentLanguage, contentLanguage);
assert.strictEqual(res.ContentType, contentType);
assert.strictEqual(res.Expires.toGMTString(),
new Date(expires).toGMTString());
assert.strictEqual(res.AcceptRanges, 'bytes');
return done();
}).catch(done);
});
it('should return the response-content-language override ' +
'instead of the stored Content-Language', async () => {
const res = await s3.send(new GetObjectCommand({
Bucket: bucketName,
Key: objectName,
ResponseContentLanguage: 'fr-FR',
}));
assert.strictEqual(res.ContentLanguage, 'fr-FR');
});
});

describe('if response content headers are set in query', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,15 @@ const bucketName = 'testgetmpubucket';
const objectName = 'key';

describe('GET multipart upload object [Cache-Control, Content-Disposition, ' +
'Content-Encoding, Expires headers]', () => {
'Content-Encoding, Content-Language, Expires headers]', () => {
withV4(sigCfg => {
let bucketUtil;
let s3;
let uploadId;
const cacheControl = 'max-age=86400';
const contentDisposition = 'attachment; filename="fname.ext";';
const contentEncoding = 'gzip,aws-chunked';
const contentLanguage = 'en-US';
// AWS Node SDK requires Date object, ISO-8601 string, or
// a UNIX timestamp for Expires header
const expires = new Date();
Expand All @@ -33,6 +34,7 @@ describe('GET multipart upload object [Cache-Control, Content-Disposition, ' +
CacheControl: cacheControl,
ContentDisposition: contentDisposition,
ContentEncoding: contentEncoding,
ContentLanguage: contentLanguage,
Expires: expires,
};
bucketUtil = new BucketUtility('default', sigCfg);
Expand Down Expand Up @@ -118,6 +120,7 @@ describe('GET multipart upload object [Cache-Control, Content-Disposition, ' +
assert.strictEqual(res.CacheControl, cacheControl);
assert.strictEqual(res.ContentDisposition, contentDisposition);
assert.strictEqual(res.ContentEncoding, 'gzip');
assert.strictEqual(res.ContentLanguage, contentLanguage);
assert.strictEqual(res.Expires.toGMTString(),
expires.toGMTString());
});
Expand Down
24 changes: 23 additions & 1 deletion tests/functional/aws-node-sdk/test/object/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const originalMetadata = {
const originalCacheControl = 'max-age=1337';
const originalContentDisposition = 'attachment; filename="1337.txt";';
const originalContentEncoding = 'base64,aws-chunked';
const originalContentLanguage = 'en-US';
const originalExpires = new Date(12345678);

const originalTagKey = 'key1';
Expand All @@ -44,6 +45,7 @@ const newMetadata = {
const newCacheControl = 'max-age=86400';
const newContentDisposition = 'attachment; filename="fname.ext";';
const newContentEncoding = 'gzip,aws-chunked';
const newContentLanguage = 'fr-FR';
const newExpires = new Date();

const newTagKey = 'key2';
Expand Down Expand Up @@ -107,6 +109,7 @@ describe('Object Copy', () => {
CacheControl: originalCacheControl,
ContentDisposition: originalContentDisposition,
ContentEncoding: originalContentEncoding,
ContentLanguage: originalContentLanguage,
Expires: originalExpires,
Tagging: originalTagging,
})).then(res => {
Expand Down Expand Up @@ -331,7 +334,7 @@ describe('Object Copy', () => {
});

it('should also copy additional headers (CacheControl, ' +
'ContentDisposition, ContentEncoding, Expires) when copying an ' +
'ContentDisposition, ContentEncoding, ContentLanguage, Expires) when copying an ' +
'object from a source bucket to a different destination bucket', done => {
s3.send(new CopyObjectCommand({ Bucket: destBucketName, Key: destObjName,
CopySource: `${sourceBucketName}/${sourceObjName}` })).then(() => {
Expand All @@ -345,6 +348,8 @@ describe('Object Copy', () => {
assert.strictEqual(res.ContentEncoding,
'base64'
);
assert.strictEqual(res.ContentLanguage,
originalContentLanguage);
assert.strictEqual(res.Expires.toGMTString(),
originalExpires.toGMTString());
done();
Expand Down Expand Up @@ -475,6 +480,7 @@ describe('Object Copy', () => {
CacheControl: newCacheControl,
ContentDisposition: newContentDisposition,
ContentEncoding: newContentEncoding,
ContentLanguage: newContentLanguage,
Expires: newExpires,
})).then(() => {
s3.send(new GetObjectCommand({ Bucket: destBucketName,
Expand All @@ -485,6 +491,7 @@ describe('Object Copy', () => {
// Should remove V4 streaming value 'aws-chunked'
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding, 'gzip');
assert.strictEqual(res.ContentLanguage, newContentLanguage);
assert.strictEqual(res.Expires.toGMTString(),
newExpires.toGMTString());
done();
Expand All @@ -498,6 +505,18 @@ describe('Object Copy', () => {
});
});

it('should drop the Content-Language if replace is included as ' +
'metadata directive header and no Content-Language is specified', async () => {
await s3.send(new CopyObjectCommand({
Bucket: destBucketName,
Key: destObjName,
CopySource: `${sourceBucketName}/${sourceObjName}`,
MetadataDirective: 'REPLACE',
}));
const res = await s3.send(new GetObjectCommand({ Bucket: destBucketName, Key: destObjName }));
assert.strictEqual(res.ContentLanguage, undefined);
});

it('should copy an object and the metadata if copy ' +
'included as metadata directive header (and ignore any new ' +
'metadata sent with copy request)', done => {
Expand Down Expand Up @@ -530,6 +549,7 @@ describe('Object Copy', () => {
CacheControl: newCacheControl,
ContentDisposition: newContentDisposition,
ContentEncoding: newContentEncoding,
ContentLanguage: newContentLanguage,
Expires: newExpires,
})).then(() => {
s3.send(new GetObjectCommand({ Bucket: destBucketName, Key: destObjName })).then(res => {
Expand All @@ -539,6 +559,8 @@ describe('Object Copy', () => {
originalContentDisposition);
assert.strictEqual(res.ContentEncoding,
'base64');
assert.strictEqual(res.ContentLanguage,
originalContentLanguage);
assert.strictEqual(res.Expires.toGMTString(),
originalExpires.toGMTString());
done();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ const bucketName = 'objectheadtestheaders';
const objectName = 'someObject';

describe('HEAD object, compatibility headers [Cache-Control, ' +
'Content-Disposition, Content-Encoding, Expires]', () => {
'Content-Disposition, Content-Encoding, Content-Language, Expires]', () => {
withV4(sigCfg => {
let bucketUtil;
let s3;
const cacheControl = 'max-age=86400';
const contentDisposition = 'attachment; filename="fname.ext";';
const contentEncoding = 'gzip,aws-chunked';
const contentLanguage = 'en-US';
// AWS Node SDK requires Date object, ISO-8601 string, or
// a UNIX timestamp for Expires header
const expires = new Date();
Expand All @@ -39,6 +40,7 @@ describe('HEAD object, compatibility headers [Cache-Control, ' +
CacheControl: cacheControl,
ContentDisposition: contentDisposition,
ContentEncoding: contentEncoding,
ContentLanguage: contentLanguage,
Expires: expires,
};
return s3.send(new PutObjectCommand(params));
Expand All @@ -63,6 +65,7 @@ describe('HEAD object, compatibility headers [Cache-Control, ' +
// to be compatible with AWS behavior
assert.strictEqual(res.ContentEncoding,
'gzip');
assert.strictEqual(res.ContentLanguage, contentLanguage);
assert.strictEqual(res.Expires.toGMTString(),
expires.toGMTString());
return done();
Expand Down
7 changes: 6 additions & 1 deletion tests/unit/api/multipartUpload.js
Original file line number Diff line number Diff line change
Expand Up @@ -566,10 +566,14 @@ describe('Multipart Upload API', () => {
const partBody = Buffer.from('I am a part\n', 'utf8');
initiateRequest.headers['x-amz-meta-stuff'] =
'I am some user metadata';
const initiateWithLanguageRequest = {
...initiateRequest,
headers: { ...initiateRequest.headers, 'content-language': 'en-US' },
};
async.waterfall([
next => bucketPut(authInfo, bucketPutRequest, log, next),
(corsHeaders, next) => initiateMultipartUpload(authInfo,
initiateRequest, log, next),
initiateWithLanguageRequest, log, next),
(result, corsHeaders, next) => parseString(result, next),
],
(err, json) => {
Expand Down Expand Up @@ -642,6 +646,7 @@ describe('Multipart Upload API', () => {
assert(MD);
assert.strictEqual(MD['x-amz-meta-stuff'],
'I am some user metadata');
assert.strictEqual(MD['content-language'], 'en-US');
assert.strictEqual(MD.uploadId, testUploadId);
done();
});
Expand Down
53 changes: 53 additions & 0 deletions tests/unit/api/objectCopy.js
Original file line number Diff line number Diff line change
Expand Up @@ -403,6 +403,59 @@ describe('non-versioned objectCopy', () => {
});
});

describe('objectCopy Content-Language', () => {
const sourceContentLanguage = 'en-US';

before(done => {
cleanup();
const testPutObjectRequest = versioningTestUtils.createPutObjectRequest(
sourceBucketName, objectKey, objData[0]);
testPutObjectRequest.headers['content-language'] = sourceContentLanguage;
async.series(
[
callback => bucketPut(authInfo, putDestBucketRequest, log, callback),
callback => bucketPut(authInfo, putSourceBucketRequest, log, callback),
callback => objectPut(authInfo, testPutObjectRequest, undefined, log, callback),
],
done,
);
});

after(() => {
cleanup();
});

[
{
desc: 'keep the source Content-Language with the COPY directive',
headers: {},
expected: sourceContentLanguage,
},
{
desc: 'store the request Content-Language with the REPLACE directive',
headers: { 'x-amz-metadata-directive': 'REPLACE', 'content-language': 'fr-FR' },
expected: 'fr-FR',
},
{
desc: 'drop the Content-Language with the REPLACE directive and no header',
headers: { 'x-amz-metadata-directive': 'REPLACE' },
expected: undefined,
},
].forEach(({ desc, headers, expected }) => {
it(`should ${desc}`, done => {
const testObjectCopyRequest = _createObjectCopyRequest(destBucketName, headers);
objectCopy(authInfo, testObjectCopyRequest, sourceBucketName, objectKey, undefined, log, err => {
assert.ifError(err);
metadata.getObjectMD(destBucketName, objectKey, {}, log, (err, md) => {
assert.ifError(err);
assert.strictEqual(md['content-language'], expected);
done();
});
});
});
});
});

describe('objectCopy overheadField', () => {
beforeEach(done => {
cleanup();
Expand Down
31 changes: 31 additions & 0 deletions tests/unit/api/objectPut.js
Original file line number Diff line number Diff line change
Expand Up @@ -425,6 +425,37 @@ describe('objectPut API', () => {
});
});

[
{ desc: 'with', contentLanguage: 'en-US' },
{ desc: 'without', contentLanguage: undefined },
].forEach(({ desc, contentLanguage }) => {
it(`should store the Content-Language of an object put ${desc} it`, done => {
const headers = {};
if (contentLanguage) {
headers['content-language'] = contentLanguage;
}
const testPutObjectRequest = new DummyRequest({
bucketName,
namespace,
objectKey: objectName,
headers,
url: `/${bucketName}/${objectName}`,
calculatedHash: 'vnR+tLdVF79rPPfF+7YvOg==',
}, postBody);

bucketPut(authInfo, testPutBucketRequest, log, () => {
objectPut(authInfo, testPutObjectRequest, undefined, log, err => {
assert.ifError(err);
metadata.getObjectMD(bucketName, objectName, {}, log, (err, md) => {
assert.ifError(err);
assert.strictEqual(md['content-language'], contentLanguage);
done();
});
});
});
});
});

it('If testingMode=true and the last-modified header is given, should set last-modified accordingly', done => {
const imposedLastModified = '2024-07-19';
const testPutObjectRequest = new DummyRequest({
Expand Down
10 changes: 10 additions & 0 deletions tests/unit/utils/collectResponseHeaders.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,14 @@ describe('Middleware: Collect Response Headers', () => {
assert.strictEqual(headers['Content-Encoding'], expected);
});
});

it('should return the stored Content-Language', () => {
const headers = collectResponseHeaders({ 'content-language': 'en-US' });
assert.strictEqual(headers['Content-Language'], 'en-US');
});

it('should not return Content-Language when none is stored', () => {
const headers = collectResponseHeaders({});
assert.strictEqual(headers['Content-Language'], undefined);
});
});
Loading