Beispiel #1
0
 public function checkPreconditions($handleAsGET = false)
 {
     // chunked upload handling
     if (isset($_SERVER['HTTP_OC_CHUNKED'])) {
         $filePath = parent::getRequestUri();
         list($path, $name) = \Sabre\DAV\URLUtil::splitPath($filePath);
         $info = OC_FileChunking::decodeName($name);
         if (!empty($info)) {
             $filePath = $path . '/' . $info['name'];
             $this->overLoadedUri = $filePath;
         }
     }
     $result = parent::checkPreconditions($handleAsGET);
     $this->overLoadedUri = null;
     return $result;
 }
Beispiel #2
0
 /**
  * Patch an uri
  *
  * The WebDAV patch request can be used to modify only a part of an 
  * existing resource. If the resource does not exist yet and the first
  * offset is not 0, the request fails
  *
  * @param string $uri
  * @return void
  */
 protected function httpPatch($uri)
 {
     // Get the node. Will throw a 404 if not found
     $node = $this->server->tree->getNodeForPath($uri);
     if (!$node instanceof IFile) {
         throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
     }
     $range = $this->getHTTPUpdateRange();
     if (!$range) {
         throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
     }
     $contentType = strtolower($this->server->httpRequest->getHeader('Content-Type'));
     if ($contentType != 'application/x-sabredav-partialupdate') {
         throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
     }
     $len = $this->server->httpRequest->getHeader('Content-Length');
     // Load the begin and end data
     $start = $range[0] ? $range[0] : 0;
     $end = $range[1] ? $range[1] : $len - 1;
     // Check consistency
     if ($end < $start) {
         throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset (' . $range[1] . ') is lower than the start offset (' . $range[0] . ')');
     }
     if ($end - $start + 1 != $len) {
         throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[0] . ') and end (' . $range[1] . ') offsets');
     }
     // Checking If-None-Match and related headers.
     if (!$this->server->checkPreconditions()) {
         return;
     }
     if (!$this->server->broadcastEvent('beforeWriteContent', array($uri, $node, null))) {
         return;
     }
     $body = $this->server->httpRequest->getBody();
     $etag = $node->putRange($body, $start - 1);
     $this->server->broadcastEvent('afterWriteContent', array($uri, $node));
     $this->server->httpResponse->setHeader('Content-Length', '0');
     if ($etag) {
         $this->server->httpResponse->setHeader('ETag', $etag);
     }
     $this->server->httpResponse->sendStatus(204);
     return false;
 }
Beispiel #3
0
 /**
  * Patch an uri
  *
  * The WebDAV patch request can be used to modify only a part of an
  * existing resource. If the resource does not exist yet and the first
  * offset is not 0, the request fails
  *
  * @param string $uri
  * @return void
  */
 protected function httpPatch($uri)
 {
     // Get the node. Will throw a 404 if not found
     $node = $this->server->tree->getNodeForPath($uri);
     if (!$node instanceof IFile && !$node instanceof IPatchSupport) {
         throw new DAV\Exception\MethodNotAllowed('The target resource does not support the PATCH method.');
     }
     $range = $this->getHTTPUpdateRange();
     if (!$range) {
         throw new DAV\Exception\BadRequest('No valid "X-Update-Range" found in the headers');
     }
     $contentType = strtolower($this->server->httpRequest->getHeader('Content-Type'));
     if ($contentType != 'application/x-sabredav-partialupdate') {
         throw new DAV\Exception\UnsupportedMediaType('Unknown Content-Type header "' . $contentType . '"');
     }
     $len = $this->server->httpRequest->getHeader('Content-Length');
     if (!$len) {
         throw new DAV\Exception\LengthRequired('A Content-Length header is required');
     }
     switch ($range[0]) {
         case self::RANGE_START:
             // Calculate the end-range if it doesn't exist.
             if (!$range[2]) {
                 $range[2] = $range[1] + $len - 1;
             } else {
                 if ($range[2] < $range[1]) {
                     throw new DAV\Exception\RequestedRangeNotSatisfiable('The end offset (' . $range[2] . ') is lower than the start offset (' . $range[1] . ')');
                 }
                 if ($range[2] - $range[1] + 1 != $len) {
                     throw new DAV\Exception\RequestedRangeNotSatisfiable('Actual data length (' . $len . ') is not consistent with begin (' . $range[1] . ') and end (' . $range[2] . ') offsets');
                 }
             }
             break;
     }
     // Checking If-None-Match and related headers.
     if (!$this->server->checkPreconditions()) {
         return;
     }
     if (!$this->server->broadcastEvent('beforeWriteContent', array($uri, $node, null))) {
         return;
     }
     $body = $this->server->httpRequest->getBody();
     if ($node instanceof IPatchSupport) {
         $etag = $node->patch($body, $range[0], isset($range[1]) ? $range[1] : null);
     } else {
         // The old interface
         switch ($range[0]) {
             case self::RANGE_APPEND:
                 throw new DAV\Exception\NotImplemented('This node does not support the append syntax. Please upgrade it to IPatchSupport');
             case self::RANGE_START:
                 $etag = $node->putRange($body, $range[1]);
                 break;
             case self::RANGE_END:
                 throw new DAV\Exception\NotImplemented('This node does not support the end-range syntax. Please upgrade it to IPatchSupport');
                 break;
         }
     }
     $this->server->broadcastEvent('afterWriteContent', array($uri, $node));
     $this->server->httpResponse->setHeader('Content-Length', '0');
     if ($etag) {
         $this->server->httpResponse->setHeader('ETag', $etag);
     }
     $this->server->httpResponse->sendStatus(204);
     return false;
 }