/** * Tests that the client attempts to load a cached response from the * cache library, but fails. * * @return void */ public function test_cache_miss() { $request = new Request('welcome/index'); $cache_mock = $this->_get_cache_mock(); $request->client()->cache(HTTP_Cache::factory($cache_mock)); $cache_mock->expects($this->once())->method('get')->with($request->client()->cache()->create_cache_key($request))->will($this->returnValue(FALSE)); $response = $request->client()->execute($request); $this->assertSame(HTTP_Cache::CACHE_STATUS_MISS, $response->headers(HTTP_Cache::CACHE_STATUS_KEY)); }
/** * Tests that the client attempts to load a cached response from the * cache library, but fails. * * @return void */ public function test_cache_miss() { $route = new Route('welcome/index'); $route->defaults(array('controller' => 'Kohana_Request_CacheTest_Dummy', 'action' => 'index')); $request = new Request('welcome/index', NULL, array($route)); $cache_mock = $this->_get_cache_mock(); $request->client()->cache(HTTP_Cache::factory($cache_mock)); $cache_mock->expects($this->once())->method('get')->with($request->client()->cache()->create_cache_key($request))->will($this->returnValue(FALSE)); $response = $request->client()->execute($request); $this->assertSame(HTTP_Cache::CACHE_STATUS_MISS, $response->headers(HTTP_Cache::CACHE_STATUS_KEY)); }
/** * * @param string $url * @return string */ public static function request($url) { return Request::factory(self::build_remote_url($url), array('cache' => HTTP_Cache::factory(Cache::instance()), 'options' => array(CURLOPT_SSL_VERIFYPEER => FALSE, CURLOPT_SSL_VERIFYHOST => FALSE, CURLOPT_USERAGENT => 'Mozilla/5.0 (Windows; U; Windows NT 6.1; en-US; rv:1.9.1.2) Gecko/20090729 Firefox/3.5.2 GTB5')))->execute()->body(); }
/** * Creates a cache key for the request to use for caching * [Kohana_Response] returned by [Request::execute]. * * This is the default cache key generating logic, but can be overridden * by setting [HTTP_Cache::cache_key_callback()]. * * @param Request $request request to create key for * @param callback $callback optional callback to use instead of built-in method * @return string */ public function create_cache_key(Request $request, $callback = FALSE) { if (is_callable($callback)) { return call_user_func($callback, $request); } else { return HTTP_Cache::basic_cache_key_generator($request); } }
*/ // Set the full path to the docroot define('DOCROOT', realpath(dirname(__FILE__)) . DIRECTORY_SEPARATOR); // Make the application relative to the docroot if (!is_dir($application) and is_dir(DOCROOT . $application)) { $application = DOCROOT . $application; } // Make the modules relative to the docroot if (!is_dir($modules) and is_dir(DOCROOT . $modules)) { $modules = DOCROOT . $modules; } // Make the system relative to the docroot if (!is_dir($system) and is_dir(DOCROOT . $system)) { $system = DOCROOT . $system; } // Define the absolute paths for configured directories define('APPPATH', realpath($application) . DIRECTORY_SEPARATOR); define('MODPATH', realpath($modules) . DIRECTORY_SEPARATOR); define('SYSPATH', realpath($system) . DIRECTORY_SEPARATOR); // Clean up the configuration vars unset($application, $modules, $system); // Define the start time of the application define('KOHANA_START_TIME', microtime(TRUE)); // Bootstrap the application require APPPATH . 'bootstrap' . EXT; /** * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO']. * If no source is specified, the URI will be automatically detected. */ $cache = extension_loaded('apc') ? HTTP_Cache::factory('apc') : NULL; echo Request::factory(TRUE, $cache)->execute()->send_headers()->body();
/** * * @param string $uri * @param boolean $cache * @return Request */ public static function request($uri, $cache = FALSE) { if (strpos($uri, '-') === FALSE) { $uri = '-' . $uri; } else { if (strpos($uri, '-') > 0 and strpos($uri, '/') === FALSE) { $uri = '/' . $uri; } } if (IS_BACKEND) { $uri = ADMIN_DIR_NAME . '/api' . $uri; } else { $uri = 'api' . $uri; } $params = array(); if ($cache !== FALSE) { $params['cache'] = HTTP_Cache::factory(Cache::instance()); } return Request::factory($uri, $params); }
} /** * Define the memory usage at the start of the application, used for profiling. */ if (!defined('KOHANA_START_MEMORY')) { define('KOHANA_START_MEMORY', memory_get_usage()); } /** * Force SSL if needed. */ if (isset($_SERVER['HTTP_X_SERVER_PORT']) and $_SERVER['HTTP_X_SERVER_PORT'] === '443') { $_SERVER['HTTPS'] = '1'; } // Bootstrap the application require APPPATH . 'bootstrap' . EXT; /** * Execute the main request. A source of the URI can be passed, eg: $_SERVER['PATH_INFO']. * If no source is specified, the URI will be automatically detected. */ echo Request::factory(TRUE, HTTP_Cache::factory('file', array('cache_key_callback' => 'my_cache_key_generator')))->execute()->send_headers(TRUE)->body(); function my_cache_key_generator(Request $request) { $is_ajax = $request->is_ajax() ? '~ajax' : ''; $uri = $request->uri(); $query = $request->query(); if (!empty($query['region'])) { unset($query['region']); } $region = $request->site_code; return sha1($uri . '?' . http_build_query($query, NULL, '&') . ':' . $region . $is_ajax); }