Ejemplo n.º 1
0
 public function testGetResourceIfNoneMatchMultipleInvalidETags()
 {
     $testPath = '/collection/test.txt';
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $etag = $backend->getProperty($testPath, 'getetag')->etag;
     $req = new ezcWebdavGetRequest($testPath);
     $req->setHeader('If-None-Match', array('sometag', 'foobar'));
     $req->validateHeaders();
     $res = $backend->get($req);
     $expectedRes = new ezcWebdavGetResourceResponse(new ezcWebdavResource($testPath, $backend->getAllProperties($testPath), "Some other contents...\n"));
     $expectedRes->setHeader('ETag', $etag);
     $this->assertEquals($expectedRes, $res, 'Expected response does not match real response.', 0, 20);
 }
Ejemplo n.º 2
0
 public function testResourceDeepGet()
 {
     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/blah/fumdiidudel.txt');
     $request->validateHeaders();
     $response = $backend->get($request);
     $expectedResponse = new ezcWebdavGetResourceResponse(new ezcWebdavResource('/bar/blah/fumdiidudel.txt', $backend->initializeProperties('/bar/blah/fumdiidudel.txt'), 'Willst du an \'was Rundes denken, denk\' an einen Plastikball. Willst du \'was gesundes schenken, schenke einen Plastikball. Plastikball, Plastikball, ...'));
     $expectedResponse->setHeader('ETag', '1c4cc7ffb86ee1feec13f05fb667e806');
     $this->assertEquals($expectedResponse, $response, 'Expected response does not match real response.', 0, 20);
 }
Ejemplo n.º 3
0
 /**
  * Returns display information for a get response on a non-collection.
  *
  * This method returns the display information generated for a $response
  * object of type {@link ezcWebdavGetResourceResponse}. It returns an
  * instance of {@link ezcWebdavDisplayInformation} containing the
  * post-processed response object and the appropriate body.
  *
  * This response returns a very seldom (for this component) string
  * response, since it returns the raw content of the requested resource.
  *
  * @param ezcWebdavGetResourceResponse $response 
  * @return ezcWebdavStringDisplayInformation
  */
 protected function processGetResourceResponse(ezcWebdavGetResourceResponse $response)
 {
     // Generate Content-Type header if necessary
     if ($response->getHeader('Content-Type') === null) {
         $contentTypeProperty = $response->resource->liveProperties->get('getcontenttype');
         $contentTypeHeader = ($contentTypeProperty->mime !== null ? $contentTypeProperty->mime : 'application/octet-stream') . '; charset="' . ($contentTypeProperty->charset !== null ? $contentTypeProperty->charset : 'utf-8') . '"';
         $response->setHeader('Content-Type', $contentTypeHeader);
     }
     // Content-Length automatically send by web server
     return new ezcWebdavStringDisplayInformation($response, $response->resource->content);
 }
Ejemplo n.º 4
0
 public function testResourceDeepGet()
 {
     $backend = new ezcWebdavFileBackend($this->tempDir . 'backend/');
     $request = new ezcWebdavGetRequest('/collection/deep_collection/deep_test.txt');
     $request->validateHeaders();
     $response = $backend->get($request);
     $expectedResponse = new ezcWebdavGetResourceResponse(new ezcWebdavResource('/collection/deep_collection/deep_test.txt', $backend->getAllProperties('/collection/deep_collection/deep_test.txt'), "=========\nTest file\n=========\n\nAnd again some randome contents...\n"));
     $expectedResponse->setHeader('ETag', $backend->getProperty('/collection/deep_collection/deep_test.txt', '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;
 }