本文整理汇总了PHP中HTTP_ConditionalGet::getHeaders方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP_ConditionalGet::getHeaders方法的具体用法?PHP HTTP_ConditionalGet::getHeaders怎么用?PHP HTTP_ConditionalGet::getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类HTTP_ConditionalGet
的用法示例。
在下文中一共展示了HTTP_ConditionalGet::getHeaders方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: test_HTTP_ConditionalGet
function test_HTTP_ConditionalGet()
{
global $thisDir;
$lmTime = time() - 900;
$gmtTime = gmdate('D, d M Y H:i:s \\G\\M\\T', $lmTime);
$tests = array(array('desc' => 'client has valid If-Modified-Since', 'inm' => null, 'ims' => $gmtTime, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid If-Modified-Since with trailing semicolon', 'inm' => null, 'ims' => $gmtTime . ';', 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid ETag (non-encoded version)', 'inm' => "\"badEtagFoo\", \"pri{$lmTime}\"", 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime}\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'client has valid ETag (gzip version)', 'inm' => "\"badEtagFoo\", \"pri{$lmTime};gz\"", 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', '_responseCode' => 'HTTP/1.0 304 Not Modified', 'isValid' => true)), array('desc' => 'no conditional get', 'inm' => null, 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)), array('desc' => 'client has invalid ETag', 'inm' => '"pri' . ($lmTime - 300) . '"', 'ims' => null, 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)), array('desc' => 'client has invalid If-Modified-Since', 'inm' => null, 'ims' => gmdate('D, d M Y H:i:s \\G\\M\\T', $lmTime - 300), 'exp' => array('Vary' => 'Accept-Encoding', 'Last-Modified' => $gmtTime, 'ETag' => "\"pri{$lmTime};gz\"", 'Cache-Control' => 'max-age=0, private', 'isValid' => false)));
foreach ($tests as $test) {
// setup env
if (null === $test['inm']) {
unset($_SERVER['HTTP_IF_NONE_MATCH']);
} else {
$_SERVER['HTTP_IF_NONE_MATCH'] = get_magic_quotes_gpc() ? addslashes($test['inm']) : $test['inm'];
}
if (null === $test['ims']) {
unset($_SERVER['HTTP_IF_MODIFIED_SINCE']);
} else {
$_SERVER['HTTP_IF_MODIFIED_SINCE'] = $test['ims'];
}
$exp = $test['exp'];
$cg = new HTTP_ConditionalGet(array('lastModifiedTime' => $lmTime, 'encoding' => 'x-gzip'));
$ret = $cg->getHeaders();
$ret['isValid'] = $cg->cacheIsValid;
$passed = assertTrue($exp == $ret, 'HTTP_ConditionalGet : ' . $test['desc']);
if (__FILE__ === realpath($_SERVER['SCRIPT_FILENAME'])) {
echo "\n--- INM = {$test['inm']} / IMS = {$test['ims']}\n";
echo "Expected = " . preg_replace('/\\s+/', ' ', var_export($exp, 1)) . "\n";
echo "Returned = " . preg_replace('/\\s+/', ' ', var_export($ret, 1)) . "\n\n";
}
}
}
示例2: serve
//.........这里部分代码省略.........
if (self::$_options['encodeOutput']) {
$sendVary = true;
if (self::$_options['encodeMethod'] !== null) {
// controller specifically requested this
$contentEncoding = self::$_options['encodeMethod'];
} else {
// sniff request header
require_once 'HTTP/Encoder.php';
// depending on what the client accepts, $contentEncoding may be
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
$sendVary = !HTTP_Encoder::isBuggyIe();
}
} else {
self::$_options['encodeMethod'] = '';
// identity (no encoding)
}
// check client cache
require_once 'HTTP/ConditionalGet.php';
$cgOptions = array('lastModifiedTime' => self::$_options['lastModifiedTime'], 'isPublic' => self::$_options['isPublic'], 'encoding' => self::$_options['encodeMethod']);
if (self::$_options['maxAge'] > 0) {
$cgOptions['maxAge'] = self::$_options['maxAge'];
} elseif (self::$_options['debug']) {
$cgOptions['invalidate'] = true;
}
$cg = new HTTP_ConditionalGet($cgOptions);
if ($cg->cacheIsValid) {
// client's cache is valid
if (!self::$_options['quiet']) {
$cg->sendHeaders();
return;
} else {
return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
}
} else {
// client will need output
$headers = $cg->getHeaders();
unset($cg);
}
if (self::$_options['contentType'] === self::TYPE_CSS && self::$_options['rewriteCssUris']) {
foreach ($controller->sources as $key => $source) {
if ($source->filepath && !isset($source->minifyOptions['currentDir']) && !isset($source->minifyOptions['prependRelativePath'])) {
$source->minifyOptions['currentDir'] = dirname($source->filepath);
}
}
}
// check server cache
if (null !== self::$_cache && !self::$_options['debug']) {
// using cache
// the goal is to use only the cache methods to sniff the length and
// output the content, as they do not require ever loading the file into
// memory.
$cacheId = self::_getCacheId();
$fullCacheId = self::$_options['encodeMethod'] ? $cacheId . '.gz' : $cacheId;
// check cache for valid entry
$cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
if ($cacheIsReady) {
$cacheContentLength = self::$_cache->getSize($fullCacheId);
} else {
// generate & cache content
try {
$content = self::_combineMinify();
} catch (Exception $e) {
self::$_controller->log($e->getMessage());
if (!self::$_options['quiet']) {
示例3: serve
//.........这里部分代码省略.........
self::_setupDebug($controller->sources);
self::$_options['maxAge'] = 0;
}
// determine encoding
if (self::$_options['encodeOutput']) {
if (self::$_options['encodeMethod'] !== null) {
// controller specifically requested this
$contentEncoding = self::$_options['encodeMethod'];
} else {
// sniff request header
require_once W3TC_LIB_MINIFY_DIR . '/HTTP/Encoder.php';
// depending on what the client accepts, $contentEncoding may be
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
list(self::$_options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(self::$_options['encodeOutput']);
}
} else {
self::$_options['encodeMethod'] = '';
// identity (no encoding)
}
// check client cache
require_once W3TC_LIB_MINIFY_DIR . '/HTTP/ConditionalGet.php';
$cgOptions = array('cacheHeaders' => self::$_options['cacheHeaders'], 'lastModifiedTime' => self::$_options['lastModifiedTime'], 'isPublic' => self::$_options['isPublic'], 'encoding' => self::$_options['encodeMethod']);
if (self::$_options['maxAge'] > 0) {
$cgOptions['maxAge'] = self::$_options['maxAge'];
}
$cg = new HTTP_ConditionalGet($cgOptions);
if ($cg->cacheIsValid) {
// client's cache is valid
if (!self::$_options['quiet']) {
$cg->sendHeaders();
return;
} else {
return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
}
} else {
// client will need output
$headers = $cg->getHeaders();
unset($cg);
}
if (self::$_options['contentType'] === self::TYPE_CSS) {
reset($controller->sources);
while (list($key, $source) = each($controller->sources)) {
if (self::$_options['rewriteCssUris'] && $source->filepath && !isset($source->minifyOptions['currentDir']) && !isset($source->minifyOptions['prependRelativePath'])) {
$source->minifyOptions['currentDir'] = dirname($source->filepath);
}
$source->minifyOptions['processCssImports'] = self::$_options['processCssImports'];
}
}
// check server cache
if (null !== self::$_cache) {
// using cache
// the goal is to use only the cache methods to sniff the length and
// output the content, as they do not require ever loading the file into
// memory.
$cacheId = self::_getCacheId();
$fullCacheId = self::$_options['encodeMethod'] ? $cacheId . '.' . self::$_options['encodeMethod'] : $cacheId;
// check cache for valid entry
$cacheIsReady = self::$_cache->isValid($fullCacheId, self::$_options['lastModifiedTime']);
if ($cacheIsReady) {
$cacheContentLength = self::$_cache->getSize($fullCacheId);
} else {
// generate & cache content
$content = self::_combineMinify();
self::$_cache->store($cacheId, $content);
if (self::$_options['encodeOutput'] && function_exists('gzencode')) {
示例4: serve
//.........这里部分代码省略.........
}
// determine encoding
if ($this->options['encodeOutput']) {
$sendVary = true;
if ($this->options['encodeMethod'] !== null) {
// controller specifically requested this
$contentEncoding = $this->options['encodeMethod'];
} else {
// sniff request header
// depending on what the client accepts, $contentEncoding may be
// 'x-gzip' while our internal encodeMethod is 'gzip'. Calling
// getAcceptedEncoding(false, false) leaves out compress and deflate as options.
list($this->options['encodeMethod'], $contentEncoding) = HTTP_Encoder::getAcceptedEncoding(false, false);
$sendVary = !HTTP_Encoder::isBuggyIe();
}
} else {
$this->options['encodeMethod'] = '';
// identity (no encoding)
}
// check client cache
$cgOptions = array('lastModifiedTime' => $this->options['lastModifiedTime'], 'isPublic' => $this->options['isPublic'], 'encoding' => $this->options['encodeMethod']);
if ($this->options['maxAge'] > 0) {
$cgOptions['maxAge'] = $this->options['maxAge'];
} elseif ($this->options['debug']) {
$cgOptions['invalidate'] = true;
}
$cg = new HTTP_ConditionalGet($cgOptions);
if ($cg->cacheIsValid) {
// client's cache is valid
if (!$this->options['quiet']) {
$cg->sendHeaders();
return;
} else {
return array('success' => true, 'statusCode' => 304, 'content' => '', 'headers' => $cg->getHeaders());
}
} else {
// client will need output
$headers = $cg->getHeaders();
unset($cg);
}
if ($this->options['contentType'] === self::TYPE_CSS && $this->options['rewriteCssUris']) {
$this->setupUriRewrites();
}
if ($this->options['concatOnly']) {
$this->options['minifiers'][self::TYPE_JS] = false;
foreach ($this->sources as $key => $source) {
if ($this->options['contentType'] === self::TYPE_JS) {
$source->setMinifier("");
} elseif ($this->options['contentType'] === self::TYPE_CSS) {
$source->setMinifier(array('Minify_CSSmin', 'minify'));
$sourceOpts = $source->getMinifierOptions();
$sourceOpts['compress'] = false;
$source->setMinifierOptions($sourceOpts);
}
}
}
// check server cache
if (!$this->options['debug']) {
// using cache
// the goal is to use only the cache methods to sniff the length and
// output the content, as they do not require ever loading the file into
// memory.
$cacheId = $this->_getCacheId();
$fullCacheId = $this->options['encodeMethod'] ? $cacheId . '.gz' : $cacheId;
// check cache for valid entry
$cacheIsReady = $this->cache->isValid($fullCacheId, $this->options['lastModifiedTime']);
示例5: _checkClientCache
private static function _checkClientCache()
{
require_once 'HTTP/ConditionalGet.php';
$cgOptions = array('lastModifiedTime' => 0, 'isPublic' => true, 'encoding' => '', 'maxAge' => 1800);
$cg = new HTTP_ConditionalGet($cgOptions);
if (MINCO_CLIENT_CACHE && $cg->cacheIsValid) {
// client's cache is valid
$cg->sendHeaders();
return true;
} else {
// client will need output
self::$_headers = $cg->getHeaders();
unset($cg);
}
return false;
}