Beispiel #1
0
 /**
  * Starts the DAV Server
  *
  * @return void
  */
 public function exec()
 {
     try {
         // If nginx (pre-1.2) is used as a proxy server, and SabreDAV as an
         // origin, we must make sure we send back HTTP/1.0 if this was
         // requested.
         // This is mainly because nginx doesn't support Chunked Transfer
         // Encoding, and this forces the webserver SabreDAV is running on,
         // to buffer entire responses to calculate Content-Length.
         $this->httpResponse->defaultHttpVersion = $this->httpRequest->getHTTPVersion();
         $this->invokeMethod($this->httpRequest->getMethod(), $this->getRequestUri());
     } catch (Exception $e) {
         try {
             $this->broadcastEvent('exception', array($e));
         } catch (Exception $ignore) {
         }
         $DOM = new \DOMDocument('1.0', 'utf-8');
         $DOM->formatOutput = true;
         $error = $DOM->createElementNS('DAV:', 'd:error');
         $error->setAttribute('xmlns:s', self::NS_SABREDAV);
         $DOM->appendChild($error);
         $h = function ($v) {
             return htmlspecialchars($v, ENT_NOQUOTES, 'UTF-8');
         };
         $error->appendChild($DOM->createElement('s:exception', $h(get_class($e))));
         $error->appendChild($DOM->createElement('s:message', $h($e->getMessage())));
         if ($this->debugExceptions) {
             $error->appendChild($DOM->createElement('s:file', $h($e->getFile())));
             $error->appendChild($DOM->createElement('s:line', $h($e->getLine())));
             $error->appendChild($DOM->createElement('s:code', $h($e->getCode())));
             $error->appendChild($DOM->createElement('s:stacktrace', $h($e->getTraceAsString())));
         }
         if (self::$exposeVersion) {
             $error->appendChild($DOM->createElement('s:sabredav-version', $h(Version::VERSION)));
         }
         if ($e instanceof Exception) {
             $httpCode = $e->getHTTPCode();
             $e->serialize($this, $error);
             $headers = $e->getHTTPHeaders($this);
         } else {
             $httpCode = 500;
             $headers = array();
         }
         $headers['Content-Type'] = 'application/xml; charset=utf-8';
         $this->httpResponse->sendStatus($httpCode);
         $this->httpResponse->setHeaders($headers);
         $this->httpResponse->sendBody($DOM->saveXML());
     }
 }