diff --git a/lib/base.php b/lib/base.php index f31cf27e4d73..d929b4d2ef58 100644 --- a/lib/base.php +++ b/lib/base.php @@ -937,6 +937,11 @@ public static function handleRequest() { throw $e; } catch (Symfony\Component\Routing\Exception\ResourceNotFoundException $e) { //header('HTTP/1.0 404 Not Found'); + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); } catch (Symfony\Component\Routing\Exception\MethodNotAllowedException $e) { OC_Response::setStatus(405); return; diff --git a/lib/public/Http/HttpEvents.php b/lib/public/Http/HttpEvents.php new file mode 100644 index 000000000000..7cbc53400973 --- /dev/null +++ b/lib/public/Http/HttpEvents.php @@ -0,0 +1,65 @@ + + * + * @copyright Copyright (c) 2017, ownCloud GmbH + * @license AGPL-3.0 + * + * This code is free software: you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License, version 3, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License, version 3, + * along with this program. If not, see + * + */ + +namespace OCP\Http; + +use OCP\IRequest; +use Symfony\Component\EventDispatcher\Event; + +/** + * @since 10.0.3 + */ +class HttpEvents extends Event { + /** @var string */ + const EVENT_404 = 'resource.not_found'; + + /** @var string */ + protected $event; + /** @var IRequest */ + protected $request; + + /** + * @param string $event + * @param IRequest $request + * @since 10.0.3 + */ + public function __construct($event, $request) { + $this->event = $event; + $this->request = $request; + } + + /** + * @return string + * @since 10.0.3 + */ + public function getEvent() { + return $this->event; + } + + + /** + * @return IRequest + * @since 10.0.3 + */ + public function getRequest() { + return $this->request; + } +} diff --git a/ocs/v1.php b/ocs/v1.php index 9383526c7239..2573568f1be6 100644 --- a/ocs/v1.php +++ b/ocs/v1.php @@ -11,6 +11,7 @@ * @author Thomas Müller * @author Tom Needham * @author Vincent Petry + * @author Semih Serhat Karakaya * * @copyright Copyright (c) 2017, ownCloud GmbH * @license AGPL-3.0 @@ -34,6 +35,7 @@ use OC\User\LoginException; use Symfony\Component\Routing\Exception\ResourceNotFoundException; use Symfony\Component\Routing\Exception\MethodNotAllowedException; +use OCP\Http\HttpEvents; require_once __DIR__ . '/../lib/base.php'; @@ -63,6 +65,11 @@ OC::$server->getRouter()->match('/ocs'.\OC::$server->getRequest()->getRawPathInfo()); return; } catch (ResourceNotFoundException $e) { + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); // Fall through the not found } catch (MethodNotAllowedException $e) { OC_API::setContentType(); @@ -85,6 +92,11 @@ } catch (LoginException $e) { OC_API::respond(new Result(null, \OCP\API::RESPOND_UNAUTHORISED, 'Unauthorised'), OC_API::requestedFormat()); } catch (ResourceNotFoundException $e) { + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); OC_API::setContentType(); OC_API::notFound(); } catch (MethodNotAllowedException $e) { diff --git a/public.php b/public.php index 4d2ae976a9c9..d15f140860a1 100644 --- a/public.php +++ b/public.php @@ -44,6 +44,11 @@ if (!$pathInfo && $request->getParam('service', '') === '') { header('HTTP/1.0 404 Not Found'); + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); exit; } elseif ($request->getParam('service', '')) { $service = $request->getParam('service', ''); @@ -54,6 +59,11 @@ $file = OCP\Config::getAppValue('core', 'public_' . strip_tags($service)); if (is_null($file)) { header('HTTP/1.0 404 Not Found'); + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); exit; } diff --git a/remote.php b/remote.php index 640e96f63845..bb4524fcccba 100644 --- a/remote.php +++ b/remote.php @@ -123,6 +123,11 @@ function resolveService($service) { $request = \OC::$server->getRequest(); $pathInfo = $request->getPathInfo(); if ($pathInfo === false || $pathInfo === '') { + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); } if (!$pos = strpos($pathInfo, '/', 1)) { @@ -133,6 +138,11 @@ function resolveService($service) { $file = resolveService($service); if(is_null($file)) { + $dispatcher = \OC::$server->getEventDispatcher(); + $dispatcher->dispatch(\OCP\Http\HttpEvents::EVENT_404, new OCP\Http\HttpEvents( + \OCP\Http\HttpEvents::EVENT_404, + OC::$server->getRequest() + )); throw new RemoteException('Path not found', OC_Response::STATUS_NOT_FOUND); }