* extractRedirectInfo - convert location saved from x-amz-website header to * same format as redirectInfo saved from a put bucket website configuration * @param {string} location - location to redirect to * @return {object} redirectInfo - select key/values stored in * WebsiteConfiguration for a
(location)
| 70 | * WebsiteConfiguration for a redirect -- protocol, replaceKeyWith and hostName |
| 71 | */ |
| 72 | function extractRedirectInfo(location) { |
| 73 | const redirectInfo = { redirectLocationHeader: true }; |
| 74 | if (location.startsWith('/')) { |
| 75 | // redirect to another object in bucket |
| 76 | redirectInfo.replaceKeyWith = location.slice(1); |
| 77 | // when redirect info is set by x-amz-website-redirect-location header |
| 78 | // to another key in the same bucket |
| 79 | // AWS only returns the path in the location response header |
| 80 | redirectInfo.justPath = true; |
| 81 | } else if (location.startsWith('https')) { |
| 82 | // otherwise, redirect to another website |
| 83 | redirectInfo.protocol = 'https'; |
| 84 | redirectInfo.hostName = location.slice(8); |
| 85 | } else { |
| 86 | redirectInfo.protocol = 'http'; |
| 87 | redirectInfo.hostName = location.slice(7); |
| 88 | } |
| 89 | return redirectInfo; |
| 90 | } |
| 91 | |
| 92 | /** |
| 93 | * validateWebsiteHeader description] |