public function testGetCollectionWithMultipleAndValidETag() { $testPath = '/collection'; $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/'); $etag = $backend->getProperty($testPath, 'getetag')->etag; $req = new ezcWebdavGetRequest($testPath); $req->setHeader('If-Match', array('sometag', $etag, 'foobar')); $req->validateHeaders(); $res = $backend->get($req); $expectedRes = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection($testPath, $backend->getAllProperties($testPath), array(new ezcWebdavCollection('/collection/deep_collection'), new ezcWebdavResource('/collection/test.txt')))); $expectedRes->setHeader('ETag', $etag); $this->assertEquals($expectedRes, $res, 'Expected response does not match real response.', 0, 20); }
public function testCollectionGet() { if (version_compare(PHP_VERSION, '5.2.6', '<')) { $this->markTestSkipped('PHP DateTime broken in versions < 5.2.6'); return; } $backend = new ezcWebdavMemoryBackend(); $backend->addContents(array('foo' => 'bar', 'bar' => array('blubb' => 'Somme blubb blubbs.', 'blah' => array('fumdiidudel.txt' => 'Willst du an \'was Rundes denken, denk\' an einen Plastikball. Willst du \'was gesundes schenken, schenke einen Plastikball. Plastikball, Plastikball, ...')))); $request = new ezcWebdavGetRequest('/bar'); $request->validateHeaders(); $response = $backend->get($request); $expectedResponse = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection('/bar', $backend->initializeProperties('/bar', true), array(new ezcWebdavResource('/bar/blubb'), new ezcWebdavCollection('/bar/blah')))); $expectedResponse->setHeader('ETag', '6a764eebfa109a9ef76c113f3f608c6b'); $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20); }
/** * Serves GET requests. * * The method receives a {@link ezcWebdavGetRequest} object containing all * relevant information obout the clients request and will return an {@link * ezcWebdavErrorResponse} instance on error or an instance of {@link * ezcWebdavGetResourceResponse} or {@link ezcWebdavGetCollectionResponse} * on success, depending on the type of resource that is referenced by the * request. * * @param ezcWebdavGetRequest $request * @return ezcWebdavResponse */ public function get(ezcWebdavGetRequest $request) { $source = $request->requestUri; // Check authorization if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'))) { return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization')); } // Check if resource is available if (!$this->nodeExists($source)) { return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source); } // Verify If-[None-]Match headers if (($res = $this->checkIfMatchHeaders($request, $source)) !== null) { return $res; } $res = null; // Init if (!$this->isCollection($source)) { // Just deliver file $res = new ezcWebdavGetResourceResponse(new ezcWebdavResource($source, $this->getAllProperties($source), $this->getResourceContents($source))); } else { // Return collection with contained children $res = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection($source, $this->getAllProperties($source), $this->getCollectionMembers($source))); } // Add ETag header $res->setHeader('ETag', $this->getETag($source)); // Deliver response return $res; }
public function testCollectionGet() { $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/'); $request = new ezcWebdavGetRequest('/collection'); $request->validateHeaders(); $response = $backend->get($request); $expectedResponse = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection('/collection', $backend->getAllProperties('/collection'), array(new ezcWebdavCollection('/collection/deep_collection'), new ezcWebdavResource('/collection/test.txt')))); $expectedResponse->setHeader('ETag', $backend->getProperty('/collection', 'getetag')->etag); $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20); }
/** * Serves GET requests. * * The method receives a {@link ezcWebdavGetRequest} object containing all * relevant information obout the clients request and will return an {@link * ezcWebdavErrorResponse} instance on error or an instance of {@link * ezcWebdavGetResourceResponse} or {@link ezcWebdavGetCollectionResponse} * on success, depending on the type of resource that is referenced by the * request. * * @param ezcWebdavGetRequest $request * @return ezcWebdavResponse */ public function get(ezcWebdavGetRequest $request) { $source = $request->requestUri; // Check authorization if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'))) { return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization')); } try { // Check if resource is available if (!$this->nodeExists($source)) { return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_404, $source); } } catch (Exception $e) { return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_500, $source, $e->getMessage()); } // Verify If-[None-]Match headers if (($res = $this->checkIfMatchHeaders($request, $source)) !== null) { return $res; } $res = null; // Init if (!$this->isCollection($source)) { // Just deliver file $res = new ezcWebdavGetResourceResponse(new ezcWebdavResource($source, $this->getAllProperties($source))); $res->setHeader("AJXP-Send-File", $this->getAccessDriver()->getRessourceUrl($this->fixPath($source))); $res->setHeader("AJXP-Wrapper", $this->wrapperClassName); } else { // Return collection with contained children $res = new ezcWebdavGetCollectionResponse(new ezcWebdavCollection($source, $this->getAllProperties($source), $this->getCollectionMembers($source))); } // Add ETag header $res->setHeader('ETag', $this->getETag($source)); // Deliver response return $res; }