Skip to content

Commit

Permalink
Prevent session start if media detected
Browse files Browse the repository at this point in the history
  • Loading branch information
David Vandemaele committed Sep 23, 2021
1 parent 23f0245 commit bf76036
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 6 deletions.
7 changes: 6 additions & 1 deletion lib/Skeleton/Core/Application/Web.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,19 @@ public function run() {
/**
* Handle the media
*/
$is_media = false;
if (isset($this->config->detect_media) AND $this->config->detect_media === true OR !isset($this->config->detect_media)) {
try {
Media::detect($this->request_relative_uri);
$is_media = Media::detect($this->request_relative_uri);
} catch (\Skeleton\Core\Exception\Media\Not\Found $e) {
\Skeleton\Core\Web\HTTP\Status::code_404('media');
}
}

if ($is_media === true) {
exit;
}

/**
* Start the session
*/
Expand Down
14 changes: 9 additions & 5 deletions lib/Skeleton/Core/Web/Media.php
Original file line number Diff line number Diff line change
Expand Up @@ -470,10 +470,12 @@ private function get_mime_type() {
private static function fail() {
$application = \Skeleton\Core\Application::get();
if ($application->event_exists('media', 'not_found')) {
$application->call_event_if_exists('media', 'not_found', [ ]);
$application->call_event_if_exists('media', 'not_found');
} else {
throw new \Skeleton\Core\Exception\Media\Not\Found('File not found');
}

exit;
}

/**
Expand All @@ -482,23 +484,25 @@ private static function fail() {
* @param $request array
* @access public
*/
public static function detect($request_uri) {
public static function detect($request_uri): bool {
// Don't bother looking up /
if ($request_uri == '/') {
return;
return false;
}

$request = pathinfo($request_uri);

if (!isset($request['extension'])) {
return;
return false;
}

$classname = get_called_class();
$media = new $classname($request_uri);
if (!$media->has_known_extension()) {
return;
return false;
}

$media->serve();
return true;
}
}

0 comments on commit bf76036

Please sign in to comment.