parseCopySource - parse objectCopy or objectPutCopyPart copy source header * @param {string} apiMethod - api method * @param {string} copySourceHeader - 'x-amz-copy-source' request header * @return {object} - sourceBucket, sourceObject, sourceVersionId, parsingError
(apiMethod, copySourceHeader)
| 10 | * @return {object} - sourceBucket, sourceObject, sourceVersionId, parsingError |
| 11 | */ |
| 12 | function parseCopySource(apiMethod, copySourceHeader) { |
| 13 | if (apiMethod !== 'objectCopy' && apiMethod !== 'objectPutCopyPart') { |
| 14 | return {}; |
| 15 | } |
| 16 | const { pathname, query } = url.parse(copySourceHeader); |
| 17 | let source = querystring.unescape(pathname); |
| 18 | // If client sends the source bucket/object with a leading /, remove it |
| 19 | if (source[0] === '/') { |
| 20 | source = source.slice(1); |
| 21 | } |
| 22 | const slashSeparator = source.indexOf('/'); |
| 23 | if (slashSeparator === -1) { |
| 24 | return { parsingError: errors.InvalidArgument }; |
| 25 | } |
| 26 | // Pull the source bucket and source object separated by / |
| 27 | const sourceBucket = source.slice(0, slashSeparator); |
| 28 | const sourceObject = source.slice(slashSeparator + 1); |
| 29 | const sourceVersionId = |
| 30 | decodeVersionId(query ? querystring.parse(query) : undefined); |
| 31 | if (sourceVersionId instanceof Error) { |
| 32 | const err = sourceVersionId; |
| 33 | return { parsingError: err }; |
| 34 | } |
| 35 | |
| 36 | return { sourceBucket, sourceObject, sourceVersionId }; |
| 37 | } |
| 38 | |
| 39 | module.exports = parseCopySource; |
no test coverage detected