* 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)
| 14 | * @return {string} - return.locationType - type of location constraint |
| 15 | */ |
| 16 | function 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 | |
| 37 | module.exports = locationHeaderCheck; |
no outgoing calls
no test coverage detected