Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does Amazon CloudFront pass through set-cookie headers?

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?

like image 573
browep Avatar asked Oct 25 '12 03:10

browep


People also ask

Does CloudFront set cookies?

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.

Does CloudFront cache response headers?

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.

What is Cookie logging in CloudFront?

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.


1 Answers

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.

like image 84
Anthony DiSanti Avatar answered Oct 13 '22 22:10

Anthony DiSanti