MCPcopy
hub / github.com/scality/cloudserver / locationHeaderCheck

Function locationHeaderCheck

lib/api/apiUtils/object/locationHeaderCheck.js:16–35  ·  view source on GitHub ↗

* locationHeaderCheck - compares 'x-amz-location-constraint' header * to location constraints in config * @param {object} headers - request headers * @param {string} objectKey - key name of object * @param {string} bucketName - name of bucket * @return {undefined|Object} returns error, object,

(headers, objectKey, bucketName)

Source from the content-addressed store, hash-verified

14 * @return {string} - return.locationType - type of location constraint
15 */
16function locationHeaderCheck(headers, objectKey, bucketName) {
17 const location = headers['x-amz-location-constraint'];
18 if (location) {
19 const validLocation = config.locationConstraints[location];
20 if (!validLocation) {
21 return errorInstances.InvalidLocationConstraint.customizeDescription(
22 'Invalid location constraint specified in header');
23 }
24 const bucketMatch = validLocation.details.bucketMatch;
25 const backendKey = bucketMatch ? objectKey :
26 `${bucketName}/${objectKey}`;
27 return {
28 location,
29 key: backendKey,
30 locationType: validLocation.type,
31 };
32 }
33 // no location header was passed
34 return undefined;
35}
36
37module.exports = locationHeaderCheck;

Callers 2

objectGetFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected