Skip to content
Open
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
2 changes: 1 addition & 1 deletion modules/api/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ class Module extends \Module
}

// Requests sent to this module must start with /api/$version
$url = $request->getURI()->getPath();
$url = $request->getAttribute("unhandledURI")->getPath();
$pieces = [];
if (preg_match(
"/^\/?(v[0-9]+\.[0-9]+\.[0-9]+[^\/]*)\/(.*)/",
Expand Down
2 changes: 1 addition & 1 deletion modules/biobank/php/endpoint.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ abstract class Endpoint
ServerRequestInterface $request,
RequestHandlerInterface $handler
): ResponseInterface {
$path = trim($request->getURI()->getPath(), "/");
$path = trim($request->getAttribute("unhandledURI")->getPath(), "/");
$pathparts = explode('/', $path);

// Check if sub-handlers are supported
Expand Down
4 changes: 2 additions & 2 deletions modules/biobank/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ class Module extends \Module
{
$this->logger->debug("Module handle function called");
$resp = parent::handle($request);
$path = $request->getAttribute("unhandledURI")->getPath();
if ($resp->getStatusCode() != 404) {
$path = $request->getURI()->getPath();
if (preg_match('/(\.css)$/', $path) == 1) {
$resp = $resp->withHeader(
"Content-Type",
Expand All @@ -84,7 +84,7 @@ class Module extends \Module

$this->loris = $request->getAttribute("loris");
$pagename = $this->getName();
$path = trim($request->getURI()->getPath(), "/");
$path = trim($path, "/");
if ($path == 'optionsendpoint'
|| $path == 'poolendpoint'
|| $path == 'containerendpoint'
Expand Down
2 changes: 1 addition & 1 deletion modules/biobank/php/preparations.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Preparations implements RequestHandlerInterface
$this->loris = $request->getAttribute("loris");

$db = $this->loris->getDatabaseConnection();
$endpoint = $request->getURI()->getPath();
$endpoint = $request->getAttribute("unhandledURI")->getPath();
$pathparts = explode('/', $endpoint);
$db->delete(
'biobank_specimen_preparation',
Expand Down
2 changes: 1 addition & 1 deletion modules/candidate_profile/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class Module extends \Module
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$candIDStr = ltrim($request->getURI()->getPath(), '/');
$candIDStr = ltrim($request->getAttribute("unhandledURI")->getPath(), '/');
try {
$candID = new CandID($candIDStr);
$candidate = \Candidate::singleton($candID);
Expand Down
2 changes: 1 addition & 1 deletion modules/conflict_resolver/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class Module extends \Module
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$path = trim($request->getURI()->getPath(), "/");
$path = trim($request->getAttribute("unhandledURI")->getPath(), "/");
switch ($path) {
case 'unresolved':
$handler = new Endpoints\Unresolved($this->loris);
Expand Down
2 changes: 1 addition & 1 deletion modules/instruments/php/module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ class Module extends \Module
return $resp;
}

$path = $request->getURI()->getPath();
$path = $request->getAttribute("unhandledURI")->getPath();
$pathComponents = [];

// Breakdown path information from the request.
Expand Down
6 changes: 5 additions & 1 deletion modules/statistics/php/charts.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,11 @@ class Charts extends \NDB_Page
// Strip any prefix of '/' to ensure that we don't have an empty string
// when splitting the path, then there should be exactly 2 parts left,
// "charts", and the endpoint requested.
$url = ltrim($request->getURI()->getPath(), '/');
$url = ltrim(
$request->getAttribute("unhandledURI")->getURI()->getPath(),
'/'
);

$pathparts = explode('/', $url);
if (count($pathparts) != 2) {
return new \LORIS\Http\Response\JSON\NotFound();
Expand Down
8 changes: 5 additions & 3 deletions php/libraries/Module.class.inc
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ abstract class Module extends \LORIS\Router\PrefixRouter
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$this->logger->debug("Module handle function called");
$resp = parent::handle($request);
$moduleURI = $request->getAttribute("unhandledURI");
$resp = parent::handle($request);

if ($resp->getStatusCode() != 404) {
$path = $request->getURI()->getPath();
$path = $moduleURI->getPath();
if (preg_match('/(\.css)$/', $path) == 1) {
$resp = $resp->withHeader(
"Content-Type",
Expand All @@ -290,7 +292,7 @@ abstract class Module extends \LORIS\Router\PrefixRouter
}

$pagename = $this->getName();
$path = trim($request->getURI()->getPath(), "/");
$path = trim($moduleURI->getPath(), "/");
if (!empty($path)) {
// There is a subpage
$pagename = explode("/", $path)[0];
Expand Down
8 changes: 5 additions & 3 deletions src/Router/BaseRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ public function __construct(
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$uri = $request->getUri();
$path = $uri->getPath();
$request = $request->withAttribute("unhandledURI", $request->getURI());
$uri = $request->getUri();
$path = $uri->getPath();

// Replace multiple slashes in the URL with a single slash
$path = preg_replace("/\/+/", "/", $path);
Expand Down Expand Up @@ -157,7 +158,8 @@ public function handle(ServerRequestInterface $request) : ResponseInterface
$module->setLogger(new \PSR\Log\NullLogger);
}
$mr = new ModuleRouter($module);
$request = $request->withURI($suburi);
$request = $request->withAttribute("unhandledURI", $suburi);

return $ehandler->process($request, $mr);
}
// Legacy from .htaccess. A CandID goes to the timepoint_list
Expand Down
5 changes: 4 additions & 1 deletion src/Router/ModuleFileRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,12 +76,15 @@ public function __construct(\Module $module, string $moduledir, string $subdir,
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$uri = $request->getAttribute("unhandledURI");
$path = !empty($uri) ? $uri->getPath() : $request->getURI()->getPath();

$fullpath = (
$this->moduledir .
"/" .
$this->subdir .
"/"
. $request->getURI()->getPath()
. $path
);

if (is_file($fullpath)) {
Expand Down
8 changes: 4 additions & 4 deletions src/Router/PrefixRouter.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,11 +92,11 @@ protected function stripPrefix(string $prefix, URIInterface $uri) : URIInterface
*/
public function handle(ServerRequestInterface $request) : ResponseInterface
{
$uri = $request->getAttribute("unhandledURI");
foreach ($this->paths as $path => $subhandler) {
if ($this->hasPrefix($path, $request->getURI())) {
// Strip the prefix before passing it to the subhandler.
$newURI = $this->stripPrefix($path, $request->getURI());
$request = $request->withURI($newURI);
if ($this->hasPrefix($path, $uri)) {
$newURI = $this->stripPrefix($path, $uri);
$request = $request->withAttribute("unhandledURI", $newURI);
return $subhandler->handle($request);
}
}
Expand Down
Loading