Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This library is using the Legacy URL API for NodeJS. Because of this, some characters that no longer need to be encoded in the pathname are being encoded. This results in 404 or 403 responses from CloudFront when using S3 as an origin.
https://nodejs.org/api/url.html#url_legacy_url_api
The legacy urlObject (require('url').Url) is created and returned by the url.parse() function.
https://nodejs.org/api/url.html#url_percent_encoding_in_urls
Percent-Encoding in URLs#
URLs are permitted to only contain a certain range of characters. Any character falling outside of that range must be encoded. How such characters are encoded, and which characters to encode depends entirely on where the character is located within the structure of the URL.
(https://nodejs.org/api/url.html#url_legacy_api)[https://nodejs.org/api/url.html#url_legacy_api]
Legacy API#
Within the Legacy API, spaces (' ') and the following characters will be automatically escaped in the properties of URL objects:
< > " ` \r \n \t { } | \ ^ '
For example, the ASCII space character (' ') is encoded as %20. The ASCII forward slash (/) character is encoded as %3C.
In my case, an apostrophe was being encoded as %27 and causing a 403.
This PR offers a new method signature for getSignedUrl:
cf.getSignedUrl({ url, pathname, ... })
where url is the base url
https://cdn.mydomain.com/
and pathname is the absolute pathname on the base url, following the NodeJS URL constructor argumentsconst myURL = new URL('/foo', 'https://example.org/');
This PR also exposes getWhatwgUrl, so you can call it directly:
cf.getWhatwgUrl({ url, pathname, ... })