Skip to content

Commit

Permalink
fixes php in public folder
Browse files Browse the repository at this point in the history
  • Loading branch information
tenmajkl committed Sep 29, 2022
1 parent ebbd033 commit 299baf3
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/Lemon/Squeezer/Squeezer.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,19 +68,10 @@ public function boot(string $host, string $port)
public function handleIncomming(ConnectionInterface $connection, Request $worker_request)
{
$path = $this->application->directory.DIRECTORY_SEPARATOR.'public'.DIRECTORY_SEPARATOR.$worker_request->path();
if (file_exists($path) && !is_dir($path)) {
$extension = explode('.', $path)[1];
$content_type = isset(self::CONTENT_TYPES[$extension])
? self::CONTENT_TYPES[$extension]
: 'text/plain'
;

$connection->send(
(new Response(200, ['Content-Type' => $content_type], file_get_contents($path)))
);
if ($response = $this->handleFiles($path)) {
$connection->send($response);
return;
}

$request = $this->captureRequest($worker_request);
$this->application->add(LemonRequest::class, $request);
$this->application->add(Session::class, new Session($worker_request->sessionId()));
Expand All @@ -99,6 +90,26 @@ public function handleIncomming(ConnectionInterface $connection, Request $worker
}
}

public function handleFiles(string $path): ?Response
{
if (file_exists($path) && !is_dir($path)) {
$extension = explode('.', $path)[1];

if ($extension === 'php') {
return null;
}

$content_type = isset(self::CONTENT_TYPES[$extension])
? self::CONTENT_TYPES[$extension]
: 'text/plain'
;

return new Response(200, ['Content-Type' => $content_type], file_get_contents($path));
}

return null;
}

public function captureRequest(Request $request): LemonRequest
{
return new LemonRequest(
Expand Down

0 comments on commit 299baf3

Please sign in to comment.