public function testConfigVary()
 {
     $body = "<html><head></head><body><h1>Mysite</h1></body></html>";
     $response = new HTTPResponse($body, 200);
     Director::config()->update('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);
     HTTP::config()->update('vary', '');
     $response = new HTTPResponse($body, 200);
     HTTP::add_cache_headers($response);
     $v = $response->getHeader('Vary');
     $this->assertEmpty($v);
 }
 /**
  * Prepare the response (we can receive an assortment of response types (strings/objects/HTTPResponses) and
  * changes the controller response object appropriately
  *
  * @param HTTPResponse|Object $response
  */
 protected function prepareResponse($response)
 {
     if ($response instanceof HTTPResponse) {
         if (isset($_REQUEST['debug_request'])) {
             Debug::message("Request handler returned HTTPResponse object to {$this->class} controller;" . "returning it without modification.");
         }
         $this->setResponse($response);
     } else {
         if ($response instanceof Object && $response->hasMethod('getViewer')) {
             if (isset($_REQUEST['debug_request'])) {
                 Debug::message("Request handler {$response->class} object to {$this->class} controller;" . "rendering with template returned by {$response->class}::getViewer()");
             }
             $response = $response->getViewer($this->getAction())->process($response);
         }
         $this->getResponse()->setBody($response);
     }
     //deal with content if appropriate
     ContentNegotiator::process($this->getResponse());
     //add cache headers
     HTTP::add_cache_headers($this->getResponse());
 }
 /**
  * Skip any further processing and immediately respond with a redirect to the passed URL.
  *
  * @param string $destURL
  */
 protected static function force_redirect($destURL)
 {
     $response = new HTTPResponse();
     $response->redirect($destURL, 301);
     HTTP::add_cache_headers($response);
     // TODO: Use an exception - ATM we can be called from _config.php, before Director#handleRequest's try block
     $response->output();
     die;
 }
 /**
  * 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 HTTPResponse instance.
  *
  * @return DBHTMLText
  */
 public function outputToBrowser()
 {
     $prevState = SSViewer::config()->get('source_file_comments');
     SSViewer::config()->update('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");
     }
     SSViewer::config()->update('source_file_comments', $prevState);
     return $this->renderWith($this->getTemplates());
 }