Last active
December 10, 2015 00:28
-
-
Save colinmollenhour/4351306 to your computer and use it in GitHub Desktop.
Test reverse proxies for full ETag support.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
$etag = date('s') < 30 ? 'one' : 'two'; | |
header('Cache-Control: public, must-revalidate, max-age=60'); | |
header('X-Foo: '.$etag); | |
header('Vary: X-Foo'); | |
header('ETag: W/"X'.$etag.'X"'); | |
if (isset($_SERVER['HTTP_IF_NONE_MATCH'])) { | |
$ifNoneMatch = $_SERVER['HTTP_IF_NONE_MATCH']; | |
file_put_contents('./etagtest.log', "HIT: $ifNoneMatch\n", FILE_APPEND); | |
if (preg_match('|(?:W/)?"X'.$etag.'X"|', $ifNoneMatch)) { | |
header(':', true, 304); | |
exit; | |
} | |
} | |
file_put_contents('./etagtest.log', "MISS\n", FILE_APPEND); | |
header('Expires: '.gmdate('D, d M Y H:i:s', time() + 600).' GMT'); | |
echo '<h1>'.date('r').'</h1>'; | |
foreach ($_SERVER as $key => $value) { | |
if (strpos($key, 'HTTP_') === 0) { | |
echo "$key: $value<br/>"; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment