awslabs / awslabs/speke-reference-server
Missing Cloudfront cache behavior config for CORS
- Dominant language
- Python
- Stars
- 124
- Forks
- 50
- Avg merge
- 4d 18h
- Merged PRs (30d)
- 1
Description
As per the Cloudfront [documentation](https://docs.aws.amazon.com/AmazonCloudFront/latest/DeveloperGuide/header-caching.html#header-caching-web-cors) you need to add the `Origin` header to the whitelisted Headers on the default cache behavior. Otherwise, the requests will be missing the CORS headers when served from cache.
Example requests :
Hit from cache :
```
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< content-type: binary/octet-stream
< content-length: 16
< date: Wed, 08 Apr 2020 16:09:54 GMT
< last-modified: Tue, 31 Mar 2020 00:17:31 GMT
< etag: "59493f9fbd62894c3a89cccfee7457c7"
< x-amz-server-side-encryption: AES256
< accept-ranges: bytes
< server: AmazonS3
< x-cache: Hit from cloudfront
```
Miss from cache:
```
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< content-type: binary/octet-stream
< content-length: 16
< date: Wed, 08 Apr 2020 16:10:58 GMT
< access-control-allow-origin: *
< access-control-allow-methods: GET
< access-control-max-age: 3000
< last-modified: Tue, 31 Mar 2020 00:17:31 GMT
< etag: "59493f9fbd62894c3a89cccfee7457c7"
< x-amz-server-side-encryption: AES256
< accept-ranges: bytes
< server: AmazonS3
< x-cache: Miss from cloudfront
```
Hit from cache after whitelisting Origin :
```
* Connection state changed (MAX_CONCURRENT_STREAMS == 128)!
< HTTP/2 200
< content-type: binary/octet-stream
< content-length: 16
< date: Wed, 08 Apr 2020 16:12:32 GMT
< access-control-allow-origin: *
< access-control-allow-methods: GET
< access-control-max-age: 3000
< last-modified: Tue, 31 Mar 2020 00:17:31 GMT
< etag: "59493f9fbd62894c3a89cccfee7457c7"
< x-amz-server-side-encryption: AES256
< accept-ranges: bytes
< server: AmazonS3
< x-cache: Hit from cloudfront
```
Contributor guide
Assessment
This issue has not been assessed yet.