-
Notifications
You must be signed in to change notification settings - Fork 255
Expand file tree
/
Copy pathparseAttributesHeader.js
More file actions
25 lines (21 loc) · 1.01 KB
/
parseAttributesHeader.js
File metadata and controls
25 lines (21 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
const { errorInstances } = require('arsenal');
const { supportedGetObjectAttributes } = require('../../../../constants');
/**
* parseAttributesHeaders - Parse and validate the x-amz-object-attributes header
* @param {object} headers - request headers
* @returns {Set<string>} - set of requested attribute names
* @throws {Error} - InvalidRequest if header is missing/empty, InvalidArgument if attribute is invalid
*/
function parseAttributesHeaders(headers) {
const attributes = headers['x-amz-object-attributes']?.split(',').map(attr => attr.trim()) ?? [];
if (attributes.length === 0) {
throw errorInstances.InvalidRequest.customizeDescription(
'The x-amz-object-attributes header specifying the attributes to be retrieved is either missing or empty',
);
}
if (attributes.some(attr => !supportedGetObjectAttributes.has(attr))) {
throw errorInstances.InvalidArgument.customizeDescription('Invalid attribute name specified.');
}
return new Set(attributes);
}
module.exports = parseAttributesHeaders;