From fc52fa3ebd121f84e0de8948c7921c20ceb14984 Mon Sep 17 00:00:00 2001 From: Joachim Beck Date: Fri, 17 Sep 2021 16:12:56 +0200 Subject: [PATCH 1/2] !!!TASK: Neos 7.x support --- Classes/Http/CheckEnabledComponent.php | 24 ------------- .../Middleware/CheckEnabledMiddleware.php | 35 +++++++++++++++++++ Configuration/Settings.yaml | 9 +++-- composer.json | 2 +- 4 files changed, 40 insertions(+), 30 deletions(-) delete mode 100644 Classes/Http/CheckEnabledComponent.php create mode 100644 Classes/Http/Middleware/CheckEnabledMiddleware.php diff --git a/Classes/Http/CheckEnabledComponent.php b/Classes/Http/CheckEnabledComponent.php deleted file mode 100644 index f3e4fa1..0000000 --- a/Classes/Http/CheckEnabledComponent.php +++ /dev/null @@ -1,24 +0,0 @@ -getHttpRequest(); - $traceNameHeader = $request->getHeader("X-Fusion-Tracing"); - if (is_array($traceNameHeader) ? $traceNameHeader !== [] : $traceNameHeader !== null) { - $this->runtimeTracing->enable(is_array($traceNameHeader) ? $traceNameHeader[0] : $traceNameHeader); - } - } -} diff --git a/Classes/Http/Middleware/CheckEnabledMiddleware.php b/Classes/Http/Middleware/CheckEnabledMiddleware.php new file mode 100644 index 0000000..9fc157f --- /dev/null +++ b/Classes/Http/Middleware/CheckEnabledMiddleware.php @@ -0,0 +1,35 @@ +getHeader("X-Fusion-Tracing"); + if (is_array($traceNameHeader) ? $traceNameHeader !== [] : $traceNameHeader !== null) { + $this->runtimeTracing->enable(is_array($traceNameHeader) ? $traceNameHeader[0] : $traceNameHeader); + } + return $handler->handle($request); + } +} diff --git a/Configuration/Settings.yaml b/Configuration/Settings.yaml index 67e2f47..a0747e2 100644 --- a/Configuration/Settings.yaml +++ b/Configuration/Settings.yaml @@ -1,8 +1,7 @@ Neos: Flow: http: - chain: - 'preprocess': - chain: - 'flowpackFusionTracingCheckEnabled': - component: 'Flowpack\Fusion\Tracing\Http\CheckEnabledComponent' + middlewares: + flowpackFusionTracingCheckEnabled: + position: 'start 999' + middleware: 'Flowpack\Fusion\Tracing\Http\Middleware\CheckEnabledMiddleware' diff --git a/composer.json b/composer.json index 1095390..40d069e 100644 --- a/composer.json +++ b/composer.json @@ -4,7 +4,7 @@ "type": "neos-package", "name": "flowpack/fusion-tracing", "require": { - "neos/fusion": "^4.3 || ^5.0 || dev-master" + "neos/fusion": "^7.0 || dev-master" }, "autoload": { "psr-4": { From f6c80644b37392c469c027d13132871305ec0685 Mon Sep 17 00:00:00 2001 From: Joachim Beck Date: Tue, 12 Oct 2021 10:36:05 +0200 Subject: [PATCH 2/2] TASK: avoid is_array checks by using getHeaderLine() --- Classes/Http/Middleware/CheckEnabledMiddleware.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Classes/Http/Middleware/CheckEnabledMiddleware.php b/Classes/Http/Middleware/CheckEnabledMiddleware.php index 9fc157f..8fa4f1c 100644 --- a/Classes/Http/Middleware/CheckEnabledMiddleware.php +++ b/Classes/Http/Middleware/CheckEnabledMiddleware.php @@ -26,9 +26,9 @@ class CheckEnabledMiddleware implements MiddlewareInterface */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $traceNameHeader = $request->getHeader("X-Fusion-Tracing"); - if (is_array($traceNameHeader) ? $traceNameHeader !== [] : $traceNameHeader !== null) { - $this->runtimeTracing->enable(is_array($traceNameHeader) ? $traceNameHeader[0] : $traceNameHeader); + $traceNameHeader = $request->getHeaderLine('X-Fusion-Tracing'); + if (!empty($traceNameHeader)) { + $this->runtimeTracing->enable($traceNameHeader); } return $handler->handle($request); }