当前位置: 首页>>代码示例>>PHP>>正文


PHP HTTP_ConditionalGet::getHeaders方法代码示例

本文整理汇总了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";
        }
    }
}
开发者ID:chaoyanjie,项目名称:HiBlog,代码行数:30,代码来源:test_HTTP_ConditionalGet.php

示例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']) {
开发者ID:mover5,项目名称:imobackup,代码行数:67,代码来源:Minify.php

示例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')) {
开发者ID:nuevomediagroup,项目名称:nmg-code,代码行数:67,代码来源:Minify.php

示例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']);
开发者ID:chaoyanjie,项目名称:HiBlog,代码行数:67,代码来源:Minify.php

示例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;
 }
开发者ID:noxstyle,项目名称:c5_mainio_minco,代码行数:16,代码来源:minco_file_writer.php


注:本文中的HTTP_ConditionalGet::getHeaders方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。