From 0f894dcdfee1815b10c717eac4d80d1275f9bbfc Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 4 Feb 2024 14:16:42 +0100 Subject: [PATCH 1/2] Replace request-id middleware dependency with userland code --- composer.json | 19 ++++---- config/autoload/logger.global.php | 7 +-- .../autoload/middleware-pipeline.global.php | 2 +- config/autoload/request_id.global.php | 44 ------------------- .../test-api/Middleware/RequestIdTest.php | 30 +++++++++++++ 5 files changed, 44 insertions(+), 58 deletions(-) delete mode 100644 config/autoload/request_id.global.php create mode 100644 module/Rest/test-api/Middleware/RequestIdTest.php diff --git a/composer.json b/composer.json index 7c336b05d..c309aeefc 100644 --- a/composer.json +++ b/composer.json @@ -36,16 +36,15 @@ "league/uri": "^6.8", "matomo/matomo-php-tracker": "^3.2", "mezzio/mezzio": "^3.17", - "mezzio/mezzio-fastroute": "^3.10", + "mezzio/mezzio-fastroute": "^3.11", "mezzio/mezzio-problem-details": "^1.13", - "mezzio/mezzio-swoole": "^4.7", + "mezzio/mezzio-swoole": "^4.8", "mlocati/ip-lib": "^1.18", "mobiledetect/mobiledetectlib": "^4.8", "pagerfanta/core": "^3.8", - "php-middleware/request-id": "^4.1", "pugx/shortid-php": "^1.1", "ramsey/uuid": "^4.7", - "shlinkio/shlink-common": "^5.7.1", + "shlinkio/shlink-common": "dev-main#a309824 as 6.0", "shlinkio/shlink-config": "^2.5", "shlinkio/shlink-event-dispatcher": "^3.1", "shlinkio/shlink-importer": "^5.2.1", @@ -56,11 +55,11 @@ "spiral/roadrunner-cli": "^2.5", "spiral/roadrunner-http": "^3.1", "spiral/roadrunner-jobs": "^4.0", - "symfony/console": "^6.3", - "symfony/filesystem": "^6.3", - "symfony/lock": "^6.3", - "symfony/process": "^6.3", - "symfony/string": "^6.3" + "symfony/console": "^6.4", + "symfony/filesystem": "^6.4", + "symfony/lock": "^6.4", + "symfony/process": "^6.4", + "symfony/string": "^6.4" }, "require-dev": { "devizzent/cebe-php-openapi": "^1.0.1", @@ -76,7 +75,7 @@ "roave/security-advisories": "dev-master", "shlinkio/php-coding-standard": "~2.3.0", "shlinkio/shlink-test-utils": "^3.8.1", - "symfony/var-dumper": "^6.3", + "symfony/var-dumper": "^6.4", "veewee/composer-run-parallel": "^1.3" }, "conflict": { diff --git a/config/autoload/logger.global.php b/config/autoload/logger.global.php index 01ec40abe..9e5e31601 100644 --- a/config/autoload/logger.global.php +++ b/config/autoload/logger.global.php @@ -7,20 +7,21 @@ use Laminas\ServiceManager\Factory\InvokableFactory; use Monolog\Level; use Monolog\Logger; -use PhpMiddleware\RequestId; use Psr\Log\LoggerInterface; use Psr\Log\NullLogger; use Shlinkio\Shlink\Common\Logger\LoggerFactory; use Shlinkio\Shlink\Common\Logger\LoggerType; use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware; +use Shlinkio\Shlink\Common\Middleware\RequestIdMiddleware; use function Shlinkio\Shlink\Config\runningInRoadRunner; return (static function (): array { $common = [ 'level' => Level::Info->value, - 'processors' => [RequestId\MonologProcessor::class], - 'line_format' => '[%datetime%] [%extra.request_id%] %channel%.%level_name% - %message%', + 'processors' => [RequestIdMiddleware::class], + 'line_format' => + '[%datetime%] [%extra.' . RequestIdMiddleware::ATTRIBUTE . '%] %channel%.%level_name% - %message%', ]; return [ diff --git a/config/autoload/middleware-pipeline.global.php b/config/autoload/middleware-pipeline.global.php index cb8045e98..072937ecf 100644 --- a/config/autoload/middleware-pipeline.global.php +++ b/config/autoload/middleware-pipeline.global.php @@ -7,10 +7,10 @@ use Laminas\Stratigility\Middleware\ErrorHandler; use Mezzio\ProblemDetails; use Mezzio\Router; -use PhpMiddleware\RequestId\RequestIdMiddleware; use RKA\Middleware\IpAddress; use Shlinkio\Shlink\Common\Middleware\AccessLogMiddleware; use Shlinkio\Shlink\Common\Middleware\ContentLengthMiddleware; +use Shlinkio\Shlink\Common\Middleware\RequestIdMiddleware; return [ diff --git a/config/autoload/request_id.global.php b/config/autoload/request_id.global.php deleted file mode 100644 index 5525849a8..000000000 --- a/config/autoload/request_id.global.php +++ /dev/null @@ -1,44 +0,0 @@ - [ - 'allow_override' => true, - 'header_name' => 'X-Request-Id', - ], - - 'dependencies' => [ - 'factories' => [ - RequestId\Generator\RamseyUuid4StaticGenerator::class => InvokableFactory::class, - RequestId\RequestIdProviderFactory::class => ConfigAbstractFactory::class, - RequestId\RequestIdMiddleware::class => ConfigAbstractFactory::class, - RequestId\MonologProcessor::class => ConfigAbstractFactory::class, - ], - 'delegators' => [ - RequestId\MonologProcessor::class => [ - BackwardsCompatibleMonologProcessorDelegator::class, - ], - ], - ], - - ConfigAbstractFactory::class => [ - RequestId\RequestIdProviderFactory::class => [ - RequestId\Generator\RamseyUuid4StaticGenerator::class, - 'config.request_id.allow_override', - 'config.request_id.header_name', - ], - RequestId\RequestIdMiddleware::class => [ - RequestId\RequestIdProviderFactory::class, - 'config.request_id.header_name', - ], - RequestId\MonologProcessor::class => [RequestId\RequestIdMiddleware::class], - ], - -]; diff --git a/module/Rest/test-api/Middleware/RequestIdTest.php b/module/Rest/test-api/Middleware/RequestIdTest.php new file mode 100644 index 000000000..bdc390a7a --- /dev/null +++ b/module/Rest/test-api/Middleware/RequestIdTest.php @@ -0,0 +1,30 @@ +callApi('GET', '/health'); + self::assertTrue($response->hasHeader('X-Request-Id')); + } + + #[Test] + public function keepsProvidedRequestId(): void + { + $response = $this->callApi('GET', '/health', [ + RequestOptions::HEADERS => [ + 'X-Request-Id' => 'foobar', + ], + ]); + self::assertEquals('foobar', $response->hasHeader('X-Request-Id')); + } +} From 7c3e3442c2a201ba0c97455434dc7109c540e0ed Mon Sep 17 00:00:00 2001 From: Alejandro Celaya Date: Sun, 4 Feb 2024 14:18:16 +0100 Subject: [PATCH 2/2] Update changelog --- CHANGELOG.md | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 812818029..566ae9dca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -4,6 +4,23 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com), and this project adheres to [Semantic Versioning](https://semver.org). +## [Unreleased] +### Added +* *Nothing* + +### Changed +* [#1935](https://github.com/shlinkio/shlink/issues/1935) Replace dependency on abandoned `php-middleware/request-id` with userland simple middleware. + +### Deprecated +* *Nothing* + +### Removed +* *Nothing* + +### Fixed +* *Nothing* + + ## [3.7.3] - 2024-01-04 ### Added * *Nothing*