Skip to content

Commit

Permalink
Merge pull request #1989 from acelaya-forks/feature/request-id-lib
Browse files Browse the repository at this point in the history
Feature/request id lib
  • Loading branch information
acelaya authored Feb 4, 2024
2 parents 6017db2 + 7c3e344 commit 0ac5569
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 58 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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*
Expand Down
19 changes: 9 additions & 10 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand All @@ -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": {
Expand Down
7 changes: 4 additions & 3 deletions config/autoload/logger.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [
Expand Down
2 changes: 1 addition & 1 deletion config/autoload/middleware-pipeline.global.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 [

Expand Down
44 changes: 0 additions & 44 deletions config/autoload/request_id.global.php

This file was deleted.

30 changes: 30 additions & 0 deletions module/Rest/test-api/Middleware/RequestIdTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
<?php

declare(strict_types=1);

namespace ShlinkioApiTest\Shlink\Rest\Middleware;

use GuzzleHttp\RequestOptions;
use PHPUnit\Framework\Attributes\Test;
use Shlinkio\Shlink\TestUtils\ApiTest\ApiTestCase;

class RequestIdTest extends ApiTestCase
{
#[Test]
public function generatesRequestId(): void
{
$response = $this->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'));
}
}

0 comments on commit 0ac5569

Please sign in to comment.