When I have an origin for CloudFront that includes set-cookie
headers in the response: will CloudFront cache the set-cookie header
for the response? If not, is there a CDN that will?
CloudFront also caches the Set-Cookie headers with the object returned from the origin, and sends those Set-Cookie headers to viewers on all cache hits. For information about specifying wildcards in cookie names, see Whitelist cookies.
CloudFront does not cache responses to requests that use the other methods. For information about configuring whether your custom origin processes these methods, see the documentation for your origin.
The Cookie header in the request, including name—value pairs and the associated attributes. If you enable cookie logging, CloudFront logs the cookies in all requests regardless of which cookies you choose to forward to the origin.
The answer isn't quite as simple as "yes" or "no." Yes, CloudFront will "pass through" set-cookie headers, but no, it will not cache the set-cookie header. This can be tested by simply uploading a test page that returns a set-cookie header with a random value and repeatedly loading the page.
CloudFront will pass along request cookies and return set-cookie headers for cookies that have been whitelisted in the "Behaviors" section of a Distribution (or all cookies if so configured). Any response that includes a set-cookie header for a whitelisted cookie will not be cached.
It should also be noted that CloudFront uses the values of any whitelisted cookies in its Object IDs for the cache objects. A particularly important case is session IDs or user-specific cookies - the user will always experience a cache miss when viewing a page for the first time, as CloudFront is using both the URL and the value of the cookie to identify the cached page.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With