/** * Validates the headers set in this response. * * This method is called by {@link ezcWebdavServer} after the response * object has been created by an {@link ezcWebdavBackend}. It validates all * headers, specific to this response, for existance of required headers * and validity of all headers used. The call of the parent method is * *mandatory* to have common WebDAV and HTTP headers validated, too. * * @return void * * @throws ezcWebdavMissingHeaderException * if a required header is missing. * @throws ezcWebdavInvalidHeaderException * if a header is present, but its content does not validate. */ public function validateHeaders() { if (count($this->responses) > 0 && $this->getHeader('Content-Type') === null) { throw new ezcWebdavMissingHeaderException('Content-Type'); } parent::validateHeaders(); }
/** * Validates the headers set in this response. * * This method is called by {@link ezcWebdavServer} after the response * object has been created by an {@link ezcWebdavBackend}. It validates all * headers, specific to this response, for existance of required headers * and validity of all headers used. The call of the parent method is * *mandatory* to have common WebDAV and HTTP headers validated, too. * * @return void * * @throws ezcWebdavMissingHeaderException * if a required header is missing. * @throws ezcWebdavInvalidHeaderException * if a header is present, but its content does not validate. */ public function validateHeaders() { if (!isset($this->headers['DAV'])) { throw new ezcWebdavMissingHeaderException('DAV'); } $dav = array_map('trim', explode(',', $this->headers['DAV'])); foreach ($dav as $number) { if ($number !== self::VERSION_ONE && $number !== self::VERSION_TWO && $number !== self::VERSION_ONE_EXTENDED) { throw new ezcWebdavInvalidHeaderException('DAV', $this->headers['DAV'], 'Components must be ezcWebdavOptionsResponse::VERSION_ONE, ezcWebdavOptionsResponse::VERSION_TWO or ezcWebdavOptionsResponse::VERSION_ONE_EXTENDED'); } } // Unified spaces $this->headers['DAV'] = implode(', ', $dav); // Validate common HTTP/WebDAV headers parent::validateHeaders(); }
/** * Handle a response and send it to the WebDAV client. * * This method is part of the integral communication API between the WebDAV * client and the {@link ezcWebdavServer}. It is declared final to ensure a * minimal compatibile API between the extended classes and it is * responsible to dispatch the {@link ezcWebdavPluginRegistry} hooks. NOTE: * The plugin API is not public, yet, and will be part of a next release. * * It currently just maps internally to {@link processResponse()} and * passes the result to {@ $this->sendResponse()}. It is not recommended * that the {@link $this->processResponse()} method is overwritten, because * this one takes care about the dispatching. The {@link * $this->sendResponse()} may be overwritten, mainly for debugging, testing * and logging purposes. * * @param ezcWebdavResponse $response * @return void */ public final function handleResponse(ezcWebdavResponse $response) { // Set the Server header with information about eZ Components version // and transport implementation. $headers = ezcWebdavServer::getInstance()->headerHandler->parseHeaders(array('Server')); $response->setHeader('Server', (isset($headers['Server']) && strlen($headers['Server']) > 0 ? $headers['Server'] . '/' : '') . 'eZComponents/' . (self::VERSION === '//auto' . 'gentag//' ? 'dev' : self::VERSION) . '/' . get_class($this)); try { $response->validateHeaders(); $this->sendResponse($this->flattenResponse($this->processResponse($response))); } catch (Exception $e) { if ($response instanceof ezcWebdavErrorResponse) { // Attention: Recursion detected! throw $e; } $this->handleResponse($this->handleException($e)); throw $e; } }