/** * This event is triggered before any HTTP request is handled. * * We use this to intercept GET calls to notification nodes, and return the * proper response. * * @param string $method * @param string $path * @return void */ public function beforeMethod($method, $path) { if ($method !== 'GET') { return; } try { $node = $this->server->tree->getNodeForPath($path); } catch (DAV\Exception\NotFound $e) { return; } if (!$node instanceof Notifications\INode) { return; } if (!$this->server->checkPreconditions(true)) { return false; } $dom = new \DOMDocument('1.0', 'UTF-8'); $dom->formatOutput = true; $root = $dom->createElement('cs:notification'); foreach ($this->server->xmlNamespaces as $namespace => $prefix) { $root->setAttribute('xmlns:' . $prefix, $namespace); } $dom->appendChild($root); $node->getNotificationType()->serializeBody($this->server, $root); $this->server->httpResponse->setHeader('Content-Type', 'application/xml'); $this->server->httpResponse->setHeader('ETag', $node->getETag()); $this->server->httpResponse->sendStatus(200); $this->server->httpResponse->sendBody($dom->saveXML()); return false; }
/** */ public function testIfUnmodifiedSinceInvalidDate() { $root = new SimpleCollection('root', array(new ServerPreconditionsNode())); $server = new Server($root); $httpRequest = HTTP\Sapi::createFromServerArray(array('HTTP_IF_UNMODIFIED_SINCE' => 'Sun, 06 Nov 1984 08:49:37 CET', 'REQUEST_URI' => '/foo')); $httpResponse = new HTTP\ResponseMock(); $this->assertTrue($server->checkPreconditions($httpRequest, $httpResponse)); }