public function testViewFoundInSub() { $views = array(array('regex' => '#^/hello#', 'sub' => array(array('regex' => '#^/home/(.+)/$#', 'view' => function () { return false; }, 'name' => 'home'))), array('regex' => '#^/foo/(.+)/$#', 'view' => function () { throw new \Exception(); }, 'name' => 'foo_bar')); Conf::set('urls', $views); $headers = (object) array('METHOD' => 'GET'); $msg = new Message('dummy', 'dummy', '/hello/home/foo/', $headers, ''); $req = new \photon\http\Request($msg); list($req, $resp) = Dispatcher::dispatch($req); $this->assertEquals(false, $resp); }
/** * Process the request available on the socket. * * The socket is available for reading with recv(). */ public function processRequest($conn) { Timer::start('photon.process_request'); $uuid = request_uuid(); $mess = $conn->recv(); if ($mess->is_disconnect()) { // A client disconnect from mongrel2 before a answer was send // Use this event to cleanup your context (long polling socket, task queue, ...) $event_params = array('conn_id' => $mess->conn_id); Event::send('\\photon\\server\\Server\\processRequest::disconnect', null, $event_params); } else { // This could be converted to use server_id + listener // connection id, it will wrap but should provide enough // uniqueness to track the effect of a request in the app. $req = new \photon\http\Request($mess); $req->uuid = $uuid; $req->conn = $conn; list($req, $response) = \photon\core\Dispatcher::dispatch($req); // If the response is false, the view is simply not // sending an answer, most likely the work was pushed to // another backend. Yes, you do not need to reply after a // recv(). if (false !== $response) { if (is_string($response->content)) { $conn->reply($mess, $response->render()); } else { Log::debug(array('photon.process_request', $uuid, 'SendIterable')); $response->sendIterable($mess, $conn); } } } unset($mess); // Cleans the memory with the __destruct call. Log::perf(array('photon.process_request', $uuid, Timer::stop('photon.process_request'))); }
public function testHPKP_enable() { Conf::set('middleware_security', array('hpkp' => true, 'hpkp_options' => array('pin-sha256' => array("MASTER_KEY_IN_BASE64", "BACKUP_KEY_IN_BASE64")))); $req = HTTP::baseRequest('GET', '/'); list($req, $resp) = Dispatcher::dispatch($req); $this->assertEquals(200, $resp->status_code); $this->assertArrayHasKey('Public-Key-Pins', $resp->headers); }