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


PHP HTTP::add_cache_headers方法代码示例

本文整理汇总了PHP中HTTP::add_cache_headers方法的典型用法代码示例。如果您正苦于以下问题:PHP HTTP::add_cache_headers方法的具体用法?PHP HTTP::add_cache_headers怎么用?PHP HTTP::add_cache_headers使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在HTTP的用法示例。


在下文中一共展示了HTTP::add_cache_headers方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: testAddCacheHeaders

 public function testAddCacheHeaders()
 {
     $body = "<html><head></head><body><h1>Mysite</h1></body></html>";
     $response = new SS_HTTPResponse($body, 200);
     $this->assertEmpty($response->getHeader('Cache-Control'));
     HTTP::set_cache_age(30);
     HTTP::add_cache_headers($response);
     $this->assertNotEmpty($response->getHeader('Cache-Control'));
     // Ensure max-age is zero for development.
     Config::inst()->update('Director', 'environment_type', 'dev');
     $response = new SS_HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=0', $response->getHeader('Cache-Control'));
     // Ensure max-age setting is respected in production.
     Config::inst()->update('Director', 'environment_type', 'live');
     $response = new SS_HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=30', explode(', ', $response->getHeader('Cache-Control')));
     $this->assertNotContains('max-age=0', $response->getHeader('Cache-Control'));
     // Still "live": Ensure header's aren't overridden if already set (using purposefully different values).
     $headers = array('Vary' => '*', 'Pragma' => 'no-cache', 'Cache-Control' => 'max-age=0, no-cache, no-store');
     $response = new SS_HTTPResponse($body, 200);
     foreach ($headers as $name => $value) {
         $response->addHeader($name, $value);
     }
     HTTP::add_cache_headers($response);
     foreach ($headers as $name => $value) {
         $this->assertEquals($value, $response->getHeader($name));
     }
 }
开发者ID:ivoba,项目名称:silverstripe-framework,代码行数:30,代码来源:HTTPTest.php

示例2: getJobStatus

 public function getJobStatus()
 {
     // Set headers
     HTTP::set_cache_age(0);
     HTTP::add_cache_headers($this->response);
     $this->response->addHeader('Content-Type', 'application/json')->addHeader('Content-Encoding', 'UTF-8')->addHeader('X-Content-Type-Options', 'nosniff');
     // Format status
     $track = BrokenExternalPageTrackStatus::get_latest();
     if ($track) {
         return json_encode(array('TrackID' => $track->ID, 'Status' => $track->Status, 'Completed' => $track->getCompletedPages(), 'Total' => $track->getTotalPages()));
     }
 }
开发者ID:govtnz,项目名称:silverstripe-externallinks,代码行数:12,代码来源:CMSExternalLinks.php

示例3: handleRequest

 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     try {
         $this->pushCurrent();
         $auth = $this->webserviceAuthenticator->authenticate($request);
         if (!$auth) {
             throw new WebServiceException(403, 'User not found');
         }
         // borrowed from Controller
         $this->urlParams = $request->allParams();
         $this->request = $request;
         $this->response = new SS_HTTPResponse();
         $this->setDataModel($model);
         $this->extend('onBeforeInit');
         $this->init();
         $this->extend('onAfterInit');
         if ($this->response->isFinished()) {
             $this->popCurrent();
             return $this->response;
         }
         $response = $this->handleService($request, $model);
         if (self::has_curr()) {
             $this->popCurrent();
         }
         if ($response instanceof SS_HTTPResponse) {
             $response->addHeader('Content-Type', 'application/' . $this->format);
         }
         HTTP::add_cache_headers($this->response);
         return $response;
     } catch (WebServiceException $exception) {
         $this->response = new SS_HTTPResponse();
         $this->response->setStatusCode($exception->status);
         $this->response->setBody($this->ajaxResponse($exception->getMessage(), $exception->status));
     } catch (SS_HTTPResponse_Exception $e) {
         $this->response = $e->getResponse();
         $this->response->setBody($this->ajaxResponse($e->getMessage(), $e->getCode()));
     } catch (Exception $exception) {
         $code = 500;
         // check type explicitly in case the Restricted Objects module isn't installed
         if (class_exists('PermissionDeniedException') && $exception instanceof PermissionDeniedException) {
             $code = 403;
         }
         $this->response = new SS_HTTPResponse();
         $this->response->setStatusCode($code);
         $this->response->setBody($this->ajaxResponse($exception->getMessage(), $code));
     }
     return $this->response;
 }
开发者ID:helpfulrobot,项目名称:silverstripe-webservices,代码行数:48,代码来源:WebServiceController.php

示例4: testAddCacheHeaders

 public function testAddCacheHeaders()
 {
     $body = "<html><head></head><body><h1>Mysite</h1></body></html>";
     $response = new SS_HTTPResponse($body, 200);
     $this->assertEmpty($response->getHeader('Cache-Control'));
     HTTP::set_cache_age(30);
     HTTP::add_cache_headers($response);
     $this->assertNotEmpty($response->getHeader('Cache-Control'));
     Config::inst()->update('Director', 'environment_type', 'dev');
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=0', $response->getHeader('Cache-Control'));
     Config::inst()->update('Director', 'environment_type', 'live');
     HTTP::add_cache_headers($response);
     $this->assertContains('max-age=30', explode(', ', $response->getHeader('Cache-Control')));
     $this->assertNotContains('max-age=0', $response->getHeader('Cache-Control'));
 }
开发者ID:miamollie,项目名称:echoAerial,代码行数:16,代码来源:HTTPTest.php

示例5: testConfigVary

 public function testConfigVary()
 {
     $body = "<html><head></head><body><h1>Mysite</h1></body></html>";
     $response = new SS_HTTPResponse($body, 200);
     Config::inst()->update('Director', 'environment_type', 'live');
     HTTP::set_cache_age(30);
     HTTP::add_cache_headers($response);
     $v = $response->getHeader('Vary');
     $this->assertNotEmpty($v);
     $this->assertContains("Cookie", $v);
     $this->assertContains("X-Forwarded-Protocol", $v);
     $this->assertContains("User-Agent", $v);
     $this->assertContains("Accept", $v);
     Config::inst()->update('HTTP', 'vary', '');
     $response = new SS_HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $v = $response->getHeader('Vary');
     $this->assertEmpty($v);
 }
开发者ID:jacobbuck,项目名称:silverstripe-framework,代码行数:19,代码来源:HTTPTest.php

示例6: onBeforeInit

 /**
  * @return SS_HTTPResponse
  */
 public function onBeforeInit()
 {
     $config = SiteConfig::current_site_config();
     // If Maintenance Mode is Off, skip processing
     if (!$config->MaintenanceMode) {
         return;
     }
     // Check if the visitor is Admin OR if they have an allowed IP.
     if (Permission::check('VIEW_SITE_MAINTENANCE_MODE') || Permission::check('ADMIN') || $this->hasAllowedIP()) {
         return;
     }
     // Are we already on the UtilityPage? If so, skip processing.
     if ($this->owner instanceof UtilityPage_Controller) {
         return;
     }
     // Fetch our utility page instance now.
     /**
      * @var Page $utilityPage
      */
     $utilityPage = UtilityPage::get()->first();
     if (!$utilityPage) {
         return;
     }
     // We need a utility page before we can do anything.
     // Are we configured to prevent redirection to the UtilityPage URL?
     if ($utilityPage->config()->DisableRedirect) {
         // Process the request internally to ensure that the URL is maintained
         // (instead of redirecting to the maintenance page's URL) and skip any further processing.
         $controller = ModelAsController::controller_for($utilityPage);
         $response = $controller->handleRequest(new SS_HTTPRequest('GET', ''), DataModel::inst());
         HTTP::add_cache_headers($response);
         $response->output();
         die;
     }
     // Default: Skip any further processing and immediately respond with a redirect to the UtilityPage.
     $response = new SS_HTTPResponse();
     $response->redirect($utilityPage->AbsoluteLink(), 302);
     HTTP::add_cache_headers($response);
     $response->output();
     die;
 }
开发者ID:hemant-chakka,项目名称:awss,代码行数:44,代码来源:MaintenanceModeExtension.php

示例7: outputToBrowser

 /**
  * Output the feed to the browser.
  *
  * TODO: Pass $response object to ->outputToBrowser() to loosen dependence on global state for easier testing/prototyping so dev can inject custom SS_HTTPResponse instance.
  *
  * @return	HTMLText
  */
 public function outputToBrowser()
 {
     $prevState = Config::inst()->get('SSViewer', 'source_file_comments');
     Config::inst()->update('SSViewer', 'source_file_comments', false);
     $response = Controller::curr()->getResponse();
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         $response->addHeader("Last-Modified", gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         $response->addHeader("Content-Type", "application/rss+xml; charset=utf-8");
     }
     Config::inst()->update('SSViewer', 'source_file_comments', $prevState);
     return $this->renderWith($this->getTemplate());
 }
开发者ID:aaronleslie,项目名称:aaronunix,代码行数:26,代码来源:RSSFeed.php

示例8: outputToBrowser

 /**
  * Output the feed to the browser
  */
 public function outputToBrowser()
 {
     $prevState = SSViewer::get_source_file_comments();
     SSViewer::set_source_file_comments(false);
     if (is_int($this->lastModified)) {
         HTTP::register_modification_timestamp($this->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $this->lastModified) . ' GMT');
     }
     if (!empty($this->etag)) {
         HTTP::register_etag($this->etag);
     }
     if (!headers_sent()) {
         HTTP::add_cache_headers();
         header("Content-type: text/xml");
     }
     SSViewer::set_source_file_comments($prevState);
     return $this->renderWith($this->getTemplate());
 }
开发者ID:normann,项目名称:sapphire,代码行数:21,代码来源:RSSFeed.php

示例9: run


//.........这里部分代码省略.........
             if (!isset($funcName) && ($defaultAction = $form->defaultAction())) {
                 $funcName = $defaultAction->actionName();
             }
             if (isset($funcName)) {
                 $form->setButtonClicked($funcName);
             }
         } else {
             user_error("No form (" . Session::get('CMSMain.currentPage') . ") returned by {$formController->class}->{$_REQUEST['executeForm']}", E_USER_WARNING);
         }
         if (isset($_GET['debug_profile'])) {
             Profiler::unmark("Controller", "populate form");
         }
         if (!isset($funcName)) {
             user_error("No action button has been clicked in this form executon, and no default has been allowed", E_USER_ERROR);
         }
         // Protection against CSRF attacks
         if ($form->securityTokenEnabled()) {
             $securityID = Session::get('SecurityID');
             if (!$securityID || !isset($this->requestParams['SecurityID']) || $securityID != $this->requestParams['SecurityID']) {
                 // Don't show error on live sites, as spammers create a million of these
                 if (!Director::isLive()) {
                     trigger_error("Security ID doesn't match, possible CRSF attack.", E_USER_ERROR);
                 } else {
                     die;
                 }
             }
         }
         // First, try a handler method on the controller
         if ($this->hasMethod($funcName) || !$form) {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$this->class}::{$funcName} (controller action)");
             }
             $result = $this->{$funcName}($this->requestParams, $form);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$this->class}::{$funcName} (controller action)");
             }
             // Otherwise, try a handler method on the form object
         } else {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the form object");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$form->class}::{$funcName} (form action)");
             }
             $result = $form->{$funcName}($this->requestParams, $form);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$form->class}::{$funcName} (form action)");
             }
         }
         // Normal action
     } else {
         if (!isset($funcName)) {
             $funcName = $this->action;
         }
         if ($this->hasMethod($funcName)) {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Found function {$funcName} on the {$this->class} controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("{$this->class}::{$funcName} (controller action)");
             }
             $result = $this->{$funcName}($this->urlParams);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("{$this->class}::{$funcName} (controller action)");
             }
         } else {
             if (isset($_GET['debug_controller'])) {
                 Debug::show("Running default action for {$funcName} on the {$this->class} controller");
             }
             if (isset($_GET['debug_profile'])) {
                 Profiler::mark("Controller::defaultAction({$funcName})");
             }
             $result = $this->defaultAction($funcName, $this->urlParams);
             if (isset($_GET['debug_profile'])) {
                 Profiler::unmark("Controller::defaultAction({$funcName})");
             }
         }
     }
     // If your controller function returns an array, then add that data to the
     // default template
     if (is_array($result)) {
         $extended = $this->customise($result);
         $viewer = $this->getViewer($funcName);
         $result = $viewer->process($extended);
     }
     $this->response->setBody($result);
     if ($result) {
         ContentNegotiator::process($this->response);
     }
     // Set up HTTP cache headers
     HTTP::add_cache_headers($this->response);
     if (isset($_GET['debug_profile'])) {
         Profiler::unmark("Controller", "run");
     }
     $this->popCurrent();
     return $this->response;
 }
开发者ID:ramziammar,项目名称:websites,代码行数:101,代码来源:Controller.php

示例10: handleRequest

 /**
  * Executes this controller, and return an {@link SS_HTTPResponse} object with the result.
  * 
  * This method first does a few set-up activities:
  *  - Push this controller ont to the controller stack - 
  *    see {@link Controller::curr()} for information about this.
  *  - Call {@link init()}
  *  - Defer to {@link RequestHandler->handleRequest()} to determine which action
  *    should be executed
  * 
  * Note: $requestParams['executeForm'] support was removed, 
  * make the following change in your URLs: 
  * "/?executeForm=FooBar" -> "/FooBar" 
  * Also make sure "FooBar" is in the $allowed_actions of your controller class.
  * 
  * Note: You should rarely need to overload run() - 
  * this kind of change is only really appropriate for things like nested
  * controllers - {@link ModelAsController} and {@link RootURLController} 
  * are two examples here.  If you want to make more
  * orthodox functionality, it's better to overload {@link init()} or {@link index()}.
  * 
  * Important: If you are going to overload handleRequest, 
  * make sure that you start the method with $this->pushCurrent()
  * and end the method with $this->popCurrent().  
  * Failure to do this will create weird session errors.
  * 
  * @param $request The {@link SS_HTTPRequest} object that is responsible 
  *  for distributing request parsing.
  * @return SS_HTTPResponse The response that this controller produces, 
  *  including HTTP headers such as redirection info
  */
 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->pushCurrent();
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->response = new SS_HTTPResponse();
     $this->setDataModel($model);
     $this->extend('onBeforeInit');
     // Init
     $this->baseInitCalled = false;
     $this->init();
     if (!$this->baseInitCalled) {
         user_error("init() method on class '{$this->class}' doesn't call Controller::init()." . "Make sure that you have parent::init() included.", E_USER_WARNING);
     }
     $this->extend('onAfterInit');
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         $this->popCurrent();
         return $this->response;
     }
     $body = parent::handleRequest($request, $model);
     if ($body instanceof SS_HTTPResponse) {
         if (isset($_REQUEST['debug_request'])) {
             Debug::message("Request handler returned SS_HTTPResponse object to {$this->class} controller;" . "returning it without modification.");
         }
         $this->response = $body;
     } else {
         if ($body instanceof Object && $body->hasMethod('getViewer')) {
             if (isset($_REQUEST['debug_request'])) {
                 Debug::message("Request handler {$body->class} object to {$this->class} controller;" . "rendering with template returned by {$body->class}::getViewer()");
             }
             $body = $body->getViewer($request->latestParam('Action'))->process($body);
         }
         $this->response->setBody($body);
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     $this->popCurrent();
     return $this->response;
 }
开发者ID:jakedaleweb,项目名称:AtomCodeChallenge,代码行数:74,代码来源:Controller.php

示例11: force_redirect

 /**
  * Skip any further processing and immediately respond with a redirect to the passed URL.
  *
  * @param string $destURL - The URL to redirect to
  */
 protected static function force_redirect($destURL)
 {
     $response = new SS_HTTPResponse("<h1>Your browser is not accepting header redirects</h1>" . "<p>Please <a href=\"{$destURL}\">click here</a>", 301);
     HTTP::add_cache_headers($response);
     $response->addHeader('Location', $destURL);
     // TODO: Use an exception - ATM we can be called from _config.php, before Director#handleRequest's try block
     $response->output();
     die;
 }
开发者ID:jareddreyer,项目名称:catalogue,代码行数:14,代码来源:Director.php

示例12: rss

 public function rss()
 {
     $this->setDefaultView();
     $events = $this->Events();
     foreach ($events as $event) {
         $event->Title = strip_tags($event->DateRange()) . " : " . $event->getTitle();
         $event->Description = $event->getContent();
     }
     $rss_title = $this->RSSTitle ? $this->RSSTitle : sprintf(_t("Calendar.UPCOMINGEVENTSFOR", "Upcoming Events for %s"), $this->Title);
     $rss = new RSSFeed($events, $this->Link(), $rss_title, "", "Title", "Description");
     if (is_int($rss->lastModified)) {
         HTTP::register_modification_timestamp($rss->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $rss->lastModified) . ' GMT');
     }
     if (!empty($rss->etag)) {
         HTTP::register_etag($rss->etag);
     }
     $xml = str_replace('&nbsp;', '&#160;', $rss->renderWith('RSSFeed'));
     $xml = preg_replace('/<!--(.|\\s)*?-->/', '', $xml);
     $xml = trim($xml);
     HTTP::add_cache_headers();
     $this->getResponse()->addHeader('Content-Type', 'application/rss+xml');
     echo $xml;
 }
开发者ID:andrewandante,项目名称:silverstripe-event-calendar,代码行数:24,代码来源:Calendar.php

示例13: handleRequest

	/**
	 * Handles HTTP requests.
	 * 
	 * If you are going to overload handleRequest, make sure that you start the method with $this->pushCurrent()
	 * and end the method with $this->popCurrent().  Failure to do this will create weird session errors.
	 * 
	 * @param $request The {@link HTTPRequest} object that is responsible for distributing request parsing.
	 */
	function handleRequest(HTTPRequest $request) {
		if(!$request) user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
		
		$this->pushCurrent();
		$this->urlParams = $request->allParams();
		$this->request = $request;
		$this->response = new HTTPResponse();

		// Init
		$this->baseInitCalled = false;	
		$this->init();
		if(!$this->baseInitCalled) user_error("init() method on class '$this->class' doesn't call Controller::init().  Make sure that you have parent::init() included.", E_USER_WARNING);

		// If we had a redirection or something, halt processing.
		if($this->response->isFinished()) {
			$this->popCurrent();
			return $this->response;
		}

		$body = parent::handleRequest($request);
		if($body instanceof HTTPResponse) {
			if(isset($_REQUEST['debug_request'])) Debug::message("Request handler returned HTTPResponse object to $this->class controller; returning it without modification.");
			$this->response = $body;
			
		} else {
			if(is_object($body)) {
				if(isset($_REQUEST['debug_request'])) Debug::message("Request handler $body->class object to $this->class controller;, rendering with template returned by $body->class::getViewer()");
			   $body = $body->getViewer($request->latestParam('Action'))->process($body);
			}
			
			$this->response->setBody($body);
		}


		ContentNegotiator::process($this->response);
		HTTP::add_cache_headers($this->response);

		$this->popCurrent();
		return $this->response;
	}
开发者ID:neopba,项目名称:silverstripe-book,代码行数:48,代码来源:Controller.php

示例14: rss

 public function rss()
 {
     $events = $this->getModel()->UpcomingEvents(null, $this->DefaultEventDisplay);
     foreach ($events as $event) {
         $event->Title = strip_tags($event->_Dates()) . " : " . $event->EventTitle();
         $event->Description = $event->EventContent();
     }
     $rss = new RSSFeed($events, $this->Link(), sprintf(_t("Calendar.UPCOMINGEVENTSFOR", "Upcoming Events for %s"), $this->Title), "", "Title", "Description");
     if (is_int($rss->lastModified)) {
         HTTP::register_modification_timestamp($rss->lastModified);
         header('Last-Modified: ' . gmdate("D, d M Y H:i:s", $rss->lastModified) . ' GMT');
     }
     if (!empty($rss->etag)) {
         HTTP::register_etag($rss->etag);
     }
     $xml = str_replace('&nbsp;', '&#160;', $rss->renderWith('RSSFeed'));
     $xml = preg_replace('/<!--(.|\\s)*?-->/', '', $xml);
     $xml = trim($xml);
     HTTP::add_cache_headers();
     header("Content-type: text/xml");
     echo $xml;
 }
开发者ID:racontemoi,项目名称:shibuichi,代码行数:22,代码来源:Calendar.php

示例15: handleRequest

 public function handleRequest(SS_HTTPRequest $request, DataModel $model)
 {
     if (!$request) {
         user_error("Controller::handleRequest() not passed a request!", E_USER_ERROR);
     }
     $this->urlParams = $request->allParams();
     $this->request = $request;
     $this->setDataModel($model);
     // Find our action or set to index if not found
     $action = $this->request->param("Action");
     if (!$action) {
         $action = "index";
     }
     $result = $this->{$action}($request);
     // Try to determine what response we are dealing with
     if ($result instanceof SS_HTTPResponse) {
         $this->response = $result;
     } else {
         $this->response = new SS_HTTPResponse();
         $this->response->setBody($result);
     }
     // If we had a redirection or something, halt processing.
     if ($this->response->isFinished()) {
         return $this->response;
     }
     ContentNegotiator::process($this->response);
     HTTP::add_cache_headers($this->response);
     return $this->response;
 }
开发者ID:i-lateral,项目名称:silverstripe-checkout,代码行数:29,代码来源:PaymentHandler.php


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