Beispiel #1
0
 /**
  * Serves PUT requests.
  *
  * The method receives a {@link ezcWebdavPutRequest} objects containing all
  * relevant information obout the clients request and will return an
  * instance of {@link ezcWebdavErrorResponse} on error or {@link
  * ezcWebdavPutResponse} on success.
  * 
  * @param ezcWebdavPutRequest $request 
  * @return ezcWebdavResponse
  */
 public function put(ezcWebdavPutRequest $request)
 {
     $source = $request->requestUri;
     // Check authorization
     // Need to do this before checking of node existence is checked, to
     // avoid leaking information
     if (!ezcWebdavServer::getInstance()->isAuthorized($source, $request->getHeader('Authorization'), ezcWebdavAuthorizer::ACCESS_WRITE)) {
         return $this->createUnauthorizedResponse($source, $request->getHeader('Authorization'));
     }
     // Check if parent node exists and throw a 409 otherwise
     if (!$this->nodeExists(dirname($source))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // Check if parent node is a collection, and throw a 409 otherwise
     if (!$this->isCollection(dirname($source))) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // Check if resource to be updated or created does not exists already
     // AND is a collection
     if ($this->nodeExists($source) && $this->isCollection($source)) {
         return new ezcWebdavErrorResponse(ezcWebdavResponse::STATUS_409, $source);
     }
     // @todo: RFC2616 Section 9.6 PUT requires us to send 501 on all
     // Content-* we don't support.
     // Verify If-[None-]Match headers
     if ($this->nodeExists($source) && ($res = $this->checkIfMatchHeaders($request, $source)) !== null) {
         return $res;
     }
     // Everything is OK, create or update resource.
     if (!$this->nodeExists($source)) {
         $this->createResource($source);
     }
     $this->setResourceContents($source, $request->body);
     $res = new ezcWebdavPutResponse($source);
     // Add ETag header
     $res->setHeader('ETag', $this->getETag($source));
     // Deliver response
     return $res;
 }