public function AuthcacheCookiesTestCase::extractSetCookies in Authenticated User Page Caching (Authcache) 7.2
Extract cookie records from a list of HTTP response headers.
3 calls to AuthcacheCookiesTestCase::extractSetCookies()
- AuthcacheCookiesTestCase::testCookieFunction in ./
authcache.test - Tests for authcache_add_cookie function.
- AuthcacheCookiesTestCase::testCookieHooks in ./
authcache.test - Verify that hook_authcache_cookie is called on every request.
- AuthcacheCookiesTestCase::testCookieOnSubsequentRequests in ./
authcache.test - Ensure that cookies are set only if necessary on repeating requests.
File
- ./
authcache.test, line 1778 - Tests for system.module.
Class
- AuthcacheCookiesTestCase
- Test cookie management.
Code
public function extractSetCookies($headers) {
$cookies = array();
$attribute_names = array(
'expires' => 'Expires',
'max-age' => 'Max-Age',
'domain' => 'Domain',
'path' => 'Path',
'secure' => 'Secure',
'httponly' => 'HttpOnly',
'samesite' => 'SameSite',
);
foreach ($headers as $header) {
if (preg_match('/^Set-Cookie:\\s+(.*)\\s*$/', trim($header), $matches)) {
$fields = preg_split('/\\s*;\\s/', $matches[1]);
debug($header);
$namepair = array_shift($fields);
list($name, $value) = explode('=', $namepair, 2);
$cookies[$name]['value'] = $value;
foreach ($fields as $parampair) {
$kv = explode('=', $parampair, 2);
$attr_key = strtolower($kv[0]);
$this
->assertTrue(isset($attribute_names[$attr_key]), t('Valid cookie attribute name @attr', array(
'@attr' => $kv[0],
)));
$attr_name = $attribute_names[$attr_key];
$attr_value = count($kv) === 2 ? $kv[1] : TRUE;
$cookies[$name][$attr_name] = $attr_value;
}
debug($cookies);
}
}
return $cookies;
}