Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#19 fix appended site path beeing ignored #20

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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 Classes/Action/OpcacheActionRequestFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function createRequest(OpcacheAction $action): RequestInterface
{
foreach ($this->siteFinder->getAllSites() as $site) {
$uri = $site->getRouter()->generateUri((string)$site->getRootPageId());
$uri = $uri->withPath($action->getUriPath());
$uri = $uri->withPath($uri->getPath() . $action->getUriPath());

$request = $this->requestFactory->createRequest($action->getRequestMethod(), $uri);
$request = $this->requestSignature->sign($request);
Expand Down
4 changes: 3 additions & 1 deletion Classes/Http/Middleware/OpcacheResetHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$action = new OpcacheAction(OpcacheAction::RESET);

if (strtolower($request->getMethod()) !== $action->getRequestMethod() || $request->getUri()->getPath() !== $action->getUriPath()) {
$resetPathDetected = substr_compare($request->getUri()->getPath(), $action->getUriPath(), -(strlen($action->getUriPath())), strlen($action->getUriPath())) === 0;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is impossible to read and understand. ;-) Maybe use str_(starts|ends)_with()?

Also currently it sounds like we stop processing if "our" path is detected which is contrary to what actually happens.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for pushing this wip-code to the PR.

Well str_ends_with() makes it incompatible with PHP 7.4 ...
For making it readable I introduces a speaking variable. But I'm happy about a better solution :-)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wouldn't mind requiring symfony/polyfill-php80 for this.


if (strtolower($request->getMethod()) !== $action->getRequestMethod() || !$resetPathDetected) {
return $handler->handle($request);
}

Expand Down
4 changes: 3 additions & 1 deletion Classes/Http/Middleware/OpcacheStatusHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ public function process(ServerRequestInterface $request, RequestHandlerInterface
{
$action = new OpcacheAction(OpcacheAction::STATUS);

if (strtolower($request->getMethod()) !== $action->getRequestMethod() || $request->getUri()->getPath() !== $action->getUriPath()) {
$statusPathDetected = substr_compare($request->getUri()->getPath(), $action->getUriPath(), -(strlen($action->getUriPath())), strlen($action->getUriPath())) === 0;

if (strtolower($request->getMethod()) !== $action->getRequestMethod() || !$statusPathDetected) {
return $handler->handle($request);
}

Expand Down