Are Set-Cookie headers removed from page cache
-
I would like to understand how w3-total-cache handles cookies, specifically Set-Cookie headers coming with a response. Based on some preliminary tests (see below) I now believe to understand that Set-Cookie response headers are stripped and not delivered from cache. Is my conclusion correct and is this the expected behaviour for W3 Total Cache page cache?
Test setup & Tests
Environment
WordPress version: 6.4.2
PHP version: 8.1
Active plugins:- Code Snippets
- Jetpack
- WooCommerce
- W3 Total Cache version 2.6.1
A test page under the url /page2/
An init hook to place a test cookie:add_action('init', function() { setcookie('test_cookie', '1', strtotime('+1 day')); });
Relevant config
W3 Total Cache enabled- Page cache enabled
- One cookie-based cache group
- cookie: no-cache
Observed behaviour
state: all caches have been purged – first request after cache purgecurl -s -c cookies.txt -D headers.txt https://w3dk.test.local/test2/ | \ awk 'BEGIN{dump=0}{if(dump == 1 || $0 ~ /Performance optimized.*/){dump = 1; print $0}}' && \ { echo "-------HEADERS---------"; cat headers.txt; } Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/ Page Caching using Disk: Enhanced Page cache debug info: Engine: Disk: Enhanced Cache key: w3dk.test.local/test2/_index_slash.html Creation Time: 1705114168.000s Header info: Set-Cookie: test_cookie=1; expires=Sun, 14-Jan-2024 02:49:28 GMT; Max-Age=86400 Content-Type: text/html; charset=UTF-8 Link: <https://w3dk.test.local/wp-json/>; rel="https://api.w.org/" Link: <https://w3dk.test.local/wp-json/wp/v2/pages/15>; rel="alternate"; type="application/json" Link: <https://w3dk.test.local/?p=15>; rel=shortlink Served from: w3dk.test.local @ 2024-01-13 03:49:28 by W3 Total Cache --> -------HEADERS--------- HTTP/1.1 200 OK Date: Sat, 13 Jan 2024 02:49:28 GMT Server: Apache Link: <https://w3dk.test.local/wp-json/>; rel="https://api.w.org/", <https://w3dk.test.local/wp-json/wp/v2/pages/15>; rel="alternate"; type="application/json", <https://w3dk.test.local/?p=15>; rel=shortlink Set-Cookie: test_cookie=1; expires=Sun, 14-Jan-2024 02:49:28 GMT; Max-Age=86400 Upgrade: h2,h2c Connection: Upgrade Last-Modified: Sat, 13 Jan 2024 02:49:28 GMT ETag: "6e424e9cfeb64252651c65b7eb79fbde" Vary: Accept-Encoding Referrer-Policy: no-referrer-when-downgrade Transfer-Encoding: chunked Content-Type: text/html; charset=UTF-8
state: subsequent request – page is already cached
curl -s -c cookies.txt -D headers.txt https://w3dk.test.local/test2/ | \ awk 'BEGIN{dump=0}{if(dump == 1 || $0 ~ /Performance optimized.*/){dump = 1; print $0}}' && \ { echo "-------HEADERS---------"; cat headers.txt; } Performance optimized by W3 Total Cache. Learn more: https://www.boldgrid.com/w3-total-cache/ Page Caching using Disk: Enhanced Page cache debug info: Engine: Disk: Enhanced Cache key: w3dk.test.local/test2/_index_slash.html Creation Time: 1705114168.000s Header info: Set-Cookie: test_cookie=1; expires=Sun, 14-Jan-2024 02:49:28 GMT; Max-Age=86400 Content-Type: text/html; charset=UTF-8 Link: <https://w3dk.test.local/wp-json/>; rel="https://api.w.org/" Link: <https://w3dk.test.local/wp-json/wp/v2/pages/15>; rel="alternate"; type="application/json" Link: <https://w3dk.test.local/?p=15>; rel=shortlink Served from: w3dk.test.local @ 2024-01-13 03:49:28 by W3 Total Cache --> -------HEADERS--------- HTTP/1.1 200 OK Date: Sat, 13 Jan 2024 02:49:42 GMT Server: Apache Upgrade: h2,h2c Connection: Upgrade Last-Modified: Sat, 13 Jan 2024 02:49:28 GMT ETag: "ee0a-60ecad4525a75" Accept-Ranges: bytes Content-Length: 60938 Vary: Accept-Encoding Referrer-Policy: no-referrer-when-downgrade Content-Type: text/html; charset=UTF-8
While the Set-Cookie: test_cookie=1; … header is present in the initial request (cache miss) the same cookie is absent when the request is served from cache.
- The topic ‘Are Set-Cookie headers removed from page cache’ is closed to new replies.