Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/base.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
65 changes: 65 additions & 0 deletions lib/public/Http/HttpEvents.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
<?php
/**
* @author Semih Serhat Karakaya <[email protected]>
*
* @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 <http://www.gnu.org/licenses/>
*
*/

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;
}
}
12 changes: 12 additions & 0 deletions ocs/v1.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
* @author Thomas Müller <[email protected]>
* @author Tom Needham <[email protected]>
* @author Vincent Petry <[email protected]>
* @author Semih Serhat Karakaya <[email protected]>
*
* @copyright Copyright (c) 2017, ownCloud GmbH
* @license AGPL-3.0
Expand All @@ -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';

Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down
10 changes: 10 additions & 0 deletions public.php
Original file line number Diff line number Diff line change
Expand Up @@ -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', '');
Expand All @@ -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;
}

Expand Down
10 changes: 10 additions & 0 deletions remote.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)) {
Expand All @@ -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);
}

Expand Down