Skip to content

Commit

Permalink
Drop support for openswoole
Browse files Browse the repository at this point in the history
  • Loading branch information
acelaya committed Feb 16, 2024
1 parent 3f6b243 commit 56bc086
Show file tree
Hide file tree
Showing 5 changed files with 5 additions and 31 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com), and this
* Remove support for redis URIs with just a password in place of the username (like `tcp://password@1.2.3.4`).
* Remove support for non-URL-encoded credentials in redis URIs.
* Remove `json_decode` and `json_encode` functions.
* Remove support for openswoole.

### Fixed
* *Nothing*
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ This module provides a set of useful middlewares, all registered as services in

Should be an early middleware in the pipeline. It makes use of the EntityManager that ensure the database connection is closed at the end of the request.

It should be used when serving an app with a non-blocking IO server (like Swoole or ReactPHP), which persist services between requests.
It should be used when serving an app with a non-blocking IO server (like RoadRunner or FrankenPHP), which persist services between requests.

* `IpAddress` (from [akrabat/ip-address-middleware](https://github.com/akrabat/ip-address-middleware) package):

Expand Down
4 changes: 1 addition & 3 deletions config/dependencies.config.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
use Laminas\ServiceManager\Factory\InvokableFactory;
use Psr\Log\LoggerInterface;
use RKA\Middleware\IpAddress;
use Shlinkio\Shlink\Config\Factory\SwooleInstalledFactory;
use Symfony\Component\Filesystem\Filesystem;

return [
Expand All @@ -19,7 +18,7 @@

Middleware\RequestIdMiddleware::class => InvokableFactory::class,
Middleware\CloseDbConnectionMiddleware::class => ConfigAbstractFactory::class,
Middleware\ContentLengthMiddleware::class => ConfigAbstractFactory::class,
Middleware\ContentLengthMiddleware::class => InvokableFactory::class,
Middleware\AccessLogMiddleware::class => ConfigAbstractFactory::class,
IpAddress::class => Middleware\IpAddressMiddlewareFactory::class,

Expand All @@ -29,7 +28,6 @@

ConfigAbstractFactory::class => [
Middleware\CloseDbConnectionMiddleware::class => ['em'],
Middleware\ContentLengthMiddleware::class => [SwooleInstalledFactory::SWOOLE_INSTALLED],
Middleware\AccessLogMiddleware::class => [Middleware\AccessLogMiddleware::LOGGER_SERVICE_NAME],
Logger\ErrorLogger::class => [LoggerInterface::class],
],
Expand Down
10 changes: 1 addition & 9 deletions src/Middleware/ContentLengthMiddleware.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,17 @@

namespace Shlinkio\Shlink\Common\Middleware;

use Closure;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\ServerRequestInterface;
use Psr\Http\Server\MiddlewareInterface;
use Psr\Http\Server\RequestHandlerInterface;

class ContentLengthMiddleware implements MiddlewareInterface
{
private Closure $isSwoole;

public function __construct(callable $isSwoole)
{
$this->isSwoole = Closure::fromCallable($isSwoole);
}

public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface
{
$response = $handler->handle($request);
if (($this->isSwoole)() || $response->hasHeader('Content-Length')) {
if ($response->hasHeader('Content-Length')) {
return $response;
}

Expand Down
19 changes: 1 addition & 18 deletions test/Middleware/ContentLengthMiddlewareTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,31 +16,14 @@
class ContentLengthMiddlewareTest extends TestCase
{
private ContentLengthMiddleware $middleware;
private bool $isSwoole;
private MockObject & RequestHandlerInterface $handler;

public function setUp(): void
{
$this->isSwoole = false;
$this->middleware = new ContentLengthMiddleware(fn () => $this->isSwoole);
$this->middleware = new ContentLengthMiddleware();
$this->handler = $this->createMock(RequestHandlerInterface::class);
}

#[Test]
public function responseIsReturnedAsIsWhenIsSwoole(): void
{
$this->isSwoole = true;
$respMock = $this->createMock(ResponseInterface::class);
$respMock->expects($this->never())->method('hasHeader')->with('Content-Length');
$respMock->expects($this->never())->method('getBody');
$request = ServerRequestFactory::fromGlobals();
$this->handler->expects($this->once())->method('handle')->with($request)->willReturn($respMock);

$result = $this->middleware->process($request, $this->handler);

self::assertSame($respMock, $result);
}

#[Test]
public function responseIsReturnedAsIsWhenItAlreadyHasContentLength(): void
{
Expand Down

0 comments on commit 56bc086

Please sign in to comment.