/** * Prepares the Kohana_Reponse object for * caching to nginx. This requires the object * to be flattened to a standard HTTP response * including full headers. * * // Creates a full HTTP valid response * $this->_create_nginx_cache($response); * * @param Kohana_Response response * @return string */ protected function _create_nginx_cache(Kohana_Response $response) { // Create empty cache buffer $cache = ''; // Generate HTTP header foreach ($response->headers as $key => $value) { $cache .= "{$key}: {$value}\n"; } // Check for HTTPS and secure cookie setting if (empty($_SERVER['HTTPS']) and !Cookie::$secure) { // Get the response cookies $cookies = $response->get_cookies(); // Generate cookies foreach ($cookies as $name => $value) { $cache .= 'Set-Cookie: ' . $name . '=' . Cookie::salt($name, $value['value']) . '~' . $value['value'] . '; expires: ' . gmdate('D, d M Y H:i:s T', $value['expiration']) . '; path: ' . Cookie::$path . '; domain: ' . Cookie::$domain . (Cookie::$httponly ? '; httpOnly' : '') . "\n"; } } // Create HTTP body $cache .= "\n" . $response->body; return $cache; }