Added support for AWS Cloudfront forwarded scheme header #2297
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.
Added support for AWS Cloudfront forwarded scheme header
Description
What went wrong?
I host some Grav websites in AWS EC2 instances behind AWS Cloudfront (to provide free SSL and caching). I do not have any ssl certificates installed in the EC2 instances (since Cloudfront handle it for us, such as a loadbalancer), so I actually have Cloudfront that handle HTTPS but communicates internally with the EC2 instance over HTTP. But, I recently figured out that Cloudfront does not provide the standard HTTP_X_FORWARDED_PROTO header but provide a HTTP_CLOUDFRONT_FORWARDED_PROTO header instead.
Resolution
Adding the support of this header prior to REQUEST_SCHEME because Cloudfront provide it but with the value of the internal communication scheme (in my case http).
Auto build the port from the scheme when we are in this situation because Cloudfront does not provide any kind of HTTP_X_FORWARDED_PORT header...
Extra notes
I don't know if there is any unit tests for this function, so let me know if there is some to implement or edit.