function testParseHeaders() { $client = new \arc\http\ClientStream(); $res = $client->get('https://www.ariadne-cms.org/'); $headers = \arc\http\headers::parse($client->responseHeaders); $this->assertTrue($headers[0] == 'HTTP/1.1 200 OK'); $this->assertTrue(isset($headers['Content-Type'])); }
function testCacheMultiple() { $headerString = <<<EOF HTTP/1.1 200 OK Cache-Control: public Cache-Control: max-age=300,s-maxage=900 EOF; $headers = \arc\http\headers::parse($headerString); $cachetime = \arc\http\headers::parseCacheTime($headers); $this->assertEquals(300, $cachetime); }
/** * Parse response headers to determine if and how long you may cache the response. Doesn't understand ETags. * @param string|string[] $headers Headers string or array as returned by parse() * @param bool $private Whether to store a private cache or public cache image. * @return int The number of seconds you may cache this result starting from now. */ public static function parseCacheTime($headers, $private = true) { $result = null; if (is_string($headers) || !isset($headers['Cache-Control']) && !isset($headers['Expires'])) { $headers = \arc\http\headers::parse($headers); } if (isset($headers['Cache-Control'])) { $header = self::mergeHeaders($headers['Cache-Control']); $result = self::getCacheControlTime($header, $private); } if (!isset($result) && isset($headers['Expires'])) { $result = strtotime(self::getLastHeader($headers['Expires'])) - time(); } return (int) $result; }