Skip to content
Merged
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
13 changes: 8 additions & 5 deletions .github/workflows/php.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
strategy:
fail-fast: false
matrix:
php: ['8.1', '8.5']
php: ['8.1', '8.2', '8.3', '8.4', '8.5']
steps:
- name: Checkout
uses: actions/checkout@v7
Expand All @@ -31,11 +31,11 @@ jobs:
github-token: ${{ secrets.GITHUB_TOKEN }}
coverage: none

- name: Validate Composer manifest and lock
run: composer validate --no-check-publish --no-interaction
- name: Validate Composer manifest
run: composer validate --no-check-publish --no-check-lock --no-interaction

- name: Install locked dependencies
run: composer install --prefer-dist --no-interaction --no-progress --no-scripts
- name: Resolve and install dependencies
run: composer update --prefer-dist --no-interaction --no-progress --no-scripts

- name: Check PHP syntax
run: find . -path './vendor' -prune -o -path './.git' -prune -o -name '*.php' -type f -print0 | xargs -0 -n1 php -l
Expand All @@ -48,3 +48,6 @@ jobs:
else
echo 'No test script is declared for this package.'
fi

- name: Audit dependencies
run: composer audit --abandoned=report
16 changes: 16 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,22 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [3.0.0] - 2026-11-20

### Changed
- Require Triangle Engine 9, Router 2, and Middleware 2 for Localzet Server 7.
- Preserve status, headers, and body when a handler returns a Localzet Server HTTP response.
- Read default response headers from the Engine 9 `app.http_headers` setting.
- Remove permissive wildcard CORS defaults; applications must configure allowed origins explicitly.

### Added
- Add regression coverage for response conversion, default headers, and a loopback HTTP request on Server 7.
- Add bilingual installation, migration, and security instructions.
- Expand CI coverage to PHP 8.1–8.5 and audit dependencies.

### Compatibility
- This is a major release. The 2.x line remains for applications using the previous Engine compatibility line.

## [1.0.0] - 2025-01-XX - LTS Release

### Added
Expand Down
58 changes: 58 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,61 @@
<img src="https://img.shields.io/github/license/Triangle-org/Engine-HTTP?label=%D0%9B%D0%B8%D1%86%D0%B5%D0%BD%D0%B7%D0%B8%D1%8F" alt="Лицензия">
</a>
</p>

# Triangle Engine HTTP

HTTP adapter for Triangle applications. It connects request handling to Localzet Server 7, Triangle Router, and Middleware; the application bootstrap remains responsible for configuration, routes, and listener startup.

## Compatibility

Release 3.x targets PHP 8.1+, Localzet Server 7.1+, Triangle Engine 9, Router 2, Middleware 2, and the PHP cURL extension. Release 2.x remains on the earlier Engine compatibility line. Do not mix the two dependency sets in one lock file.

## Install

```bash
composer require triangle/engine-http:^3.0
```

Follow the [installation guide](https://server.localzet.com/projects/engine-http/install) for the complete bootstrap and version checks.

## Request and response flow

Register routes before collecting the Router dispatcher:

```php
use localzet\Server\Protocols\Http\Response;
use Triangle\Router;

Router::any('/health', static fn () => new Response(
200,
['Content-Type' => 'application/json'],
'{"status":"ok"}',
));

Router::collect([]);
```

Engine HTTP sends requests through route middleware and controller resolution. A Localzet Server HTTP response keeps its status, headers, and body. Other return values become a `200` response with a string body.

## Security and limits

- Authentication and authorization belong to the application or its middleware.
- CORS is not enabled by default. Configure `app.http_headers` with explicit origins and headers when cross-origin access is required.
- PHP files under a public path are disabled by default; enable them only when the application has a clear need and a reviewable execution boundary.
- Listener, HTTP framing, worker lifecycle, and backpressure are provided by Localzet Server.

See the [request guide](https://server.localzet.com/projects/engine-http/requests), [configuration](https://server.localzet.com/projects/engine-http/architecture), and [security guide](https://server.localzet.com/projects/engine-http/security) for production setup.

## Checks

```bash
composer validate --strict --no-check-publish --no-interaction
composer run test --no-interaction
composer audit --abandoned=report
```

The test command covers response compatibility and a loopback HTTP request against Server 7.

## License

AGPL-3.0-or-later. See [LICENSE](LICENSE).
57 changes: 57 additions & 0 deletions README.ru.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# Triangle Engine HTTP

HTTP-адаптер для приложений Triangle. Он связывает обработку запросов с Localzet Server 7, Router и Middleware Triangle. Конфигурация приложения, маршруты и запуск listener-а остаются ответственностью bootstrap проекта.

## Совместимость

Версия 3.x рассчитана на PHP 8.1+, Localzet Server 7.1+, Triangle Engine 9, Router 2, Middleware 2 и расширение PHP cURL. Версия 2.x относится к прежней ветке совместимости Engine. Не смешивайте эти наборы зависимостей в одном lock-файле.

## Установка

```bash
composer require triangle/engine-http:^3.0
```

Полный порядок запуска и проверки версий описан в [руководстве по установке](https://server.localzet.com/projects/engine-http/install).

## Обработка запроса и ответа

Регистрируйте маршруты до сборки dispatcher-а Router:

```php
use localzet\Server\Protocols\Http\Response;
use Triangle\Router;

Router::any('/health', static fn () => new Response(
200,
['Content-Type' => 'application/json'],
'{"status":"ok"}',
));

Router::collect([]);
```

Engine HTTP передаёт запрос через middleware маршрута и разрешение контроллеров. HTTP-ответ Localzet Server сохраняет статус, заголовки и тело. Остальные значения превращаются в ответ `200` со строковым телом.

## Безопасность и ограничения

- Аутентификацию и проверку прав настраивает приложение или его middleware.
- CORS по умолчанию выключен. Если нужен доступ с другого origin, задайте явные origin и заголовки в `app.http_headers`.
- Выполнение PHP-файлов внутри публичного каталога по умолчанию выключено. Включайте его только при ясной необходимости и проверяемой границе исполнения.
- Listener, HTTP framing, жизненный цикл worker-ов и backpressure реализует Localzet Server.

Смотрите [обработку запросов](https://server.localzet.com/projects/engine-http/requests), [конфигурацию](https://server.localzet.com/projects/engine-http/architecture) и [руководство по безопасности](https://server.localzet.com/projects/engine-http/security).

## Проверки

```bash
composer validate --strict --no-check-publish --no-interaction
composer run test --no-interaction
composer audit --abandoned=report
```

Тесты проверяют совместимость ответов и HTTP-запрос к Server 7 через loopback.

## Лицензия

AGPL-3.0-or-later. Текст лицензии — в файле [LICENSE](LICENSE).
5 changes: 4 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
"require": {
"php": "^8.1",
"ext-curl": "*",
"triangle/engine": "^8",
"triangle/engine": "^9.0",
"triangle/router": "^2",
"triangle/middleware": "^2"
},
Expand All @@ -43,6 +43,9 @@
"require-dev": {
"rector/rector": "*"
},
"scripts": {
"test": "php tests/Server7ResponseCompatibilityTest.php && php tests/Server7HttpLoopbackTest.php"
},
"conflict": {
"triangle/engine-ws": "*"
},
Expand Down
2 changes: 1 addition & 1 deletion rector.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down
16 changes: 12 additions & 4 deletions src/App.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -29,6 +29,7 @@
use Closure;
use localzet\Server\Connection\ConnectionInterface;
use localzet\Server\Connection\TcpConnection;
use localzet\Server\Protocols\Http\Response as ServerResponse;
use Psr\Container\ContainerExceptionInterface;
use Psr\Container\NotFoundExceptionInterface;
use ReflectionException;
Expand Down Expand Up @@ -186,14 +187,14 @@ public static function getCallback(?string $plugin, string $app, $call, array $a
$call = static::resolveInject($plugin, $call, $args);
}

$callback = function ($request) use ($call, $anonymousArgs): \Triangle\Engine\Response {
$callback = function ($request) use ($call, $anonymousArgs): ServerResponse {
try {
$response = $anonymousArgs ? $call($request, ...$anonymousArgs) : $call($request);
} catch (Throwable $throwable) {
return static::exceptionResponse($throwable, $request);
}

return $response instanceof Response ? $response : new Response(200, [], static::stringify($response));
return static::normalizeResponse($response);
};

return $middlewares ? array_reduce($middlewares, fn($carry, $pipe): \Closure => function ($request) use ($carry, $pipe) {
Expand All @@ -217,7 +218,7 @@ protected static function send(mixed $connection, mixed $response, mixed $reques
if (($keepAlive === null
&& $request->protocolVersion() === '1.1')
|| $keepAlive === 'keep-alive' || $keepAlive === 'Keep-Alive'
|| ($response instanceof Response
|| ($response instanceof ServerResponse
&& $response->getHeader('Transfer-Encoding') === 'chunked')
) {
$connection->send($response);
Expand All @@ -227,6 +228,13 @@ protected static function send(mixed $connection, mixed $response, mixed $reques
$connection->close($response);
}

protected static function normalizeResponse(mixed $response): ServerResponse
{
return $response instanceof ServerResponse
? $response
: new Response(200, [], static::stringify($response));
}


protected static function getFallback(?string $plugin = '', int $status = 404): Closure
{
Expand Down
8 changes: 2 additions & 6 deletions src/Config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down Expand Up @@ -36,12 +36,8 @@
'controller_suffix' => env('CONTROLLER_SUFFIX', ''),
'controller_reuse' => env('CONTROLLER_REUSE', true),

'headers' => [
'http_headers' => [
'Content-Language' => 'ru',
'Access-Control-Allow-Origin' => '*',
'Access-Control-Allow-Credentials' => 'true',
'Access-Control-Allow-Methods' => '*',
'Access-Control-Allow-Headers' => '*',
'X-Powered-By' => 'Triangle-Core/' . Composer\InstalledVersions::getVersion('triangle/engine'),
],
];
4 changes: 2 additions & 2 deletions src/Config/exception.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand All @@ -31,7 +31,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2024 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/Config/static.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/Install.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down
2 changes: 1 addition & 1 deletion src/Support/Request.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
* @link https://github.com/Triangle-org/Http
*
* @author Ivan Zorin <creator@localzet.com>
* @copyright Copyright (c) 2023-2025 Triangle Framework Team
* @copyright Copyright © 2016-2026 Localzet Group. All rights reserved.
* @license https://www.gnu.org/licenses/agpl-3.0 GNU Affero General Public License v3.0
*
* This program is free software: you can redistribute it and/or modify
Expand Down
Loading