Upgrade amp http server

This commit is contained in:
Alexander Pankratov 2023-08-07 10:38:37 +02:00
parent 2b3d162bf3
commit 2fb2c3a9e0
2 changed files with 65 additions and 58 deletions

106
composer.lock generated
View File

@ -538,16 +538,16 @@
}, },
{ {
"name": "amphp/http-client", "name": "amphp/http-client",
"version": "v5.0.0-beta.11", "version": "v5.0.0-beta.12",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/http-client.git", "url": "https://github.com/amphp/http-client.git",
"reference": "0fd30c4ff2231b044ead0e7a5d3aedafcbca59b1" "reference": "4a962fe1d96ca0ca956401f08eb3eb72e90e5d2b"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/http-client/zipball/0fd30c4ff2231b044ead0e7a5d3aedafcbca59b1", "url": "https://api.github.com/repos/amphp/http-client/zipball/4a962fe1d96ca0ca956401f08eb3eb72e90e5d2b",
"reference": "0fd30c4ff2231b044ead0e7a5d3aedafcbca59b1", "reference": "4a962fe1d96ca0ca956401f08eb3eb72e90e5d2b",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -559,10 +559,8 @@
"amphp/socket": "^2", "amphp/socket": "^2",
"amphp/sync": "^2", "amphp/sync": "^2",
"league/uri": "^6", "league/uri": "^6",
"league/uri-components": "^2.4",
"php": ">=8.1", "php": ">=8.1",
"psr/http-message": "^1", "psr/http-message": "^1 | ^2"
"revolt/event-loop": "^1"
}, },
"require-dev": { "require-dev": {
"amphp/file": "^3", "amphp/file": "^3",
@ -624,7 +622,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/amphp/http-client/issues", "issues": "https://github.com/amphp/http-client/issues",
"source": "https://github.com/amphp/http-client/tree/v5.0.0-beta.11" "source": "https://github.com/amphp/http-client/tree/v5.0.0-beta.12"
}, },
"funding": [ "funding": [
{ {
@ -632,7 +630,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-04-13T05:19:15+00:00" "time": "2023-08-05T15:21:21+00:00"
}, },
{ {
"name": "amphp/http-client-cookies", "name": "amphp/http-client-cookies",
@ -717,12 +715,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/http-server.git", "url": "https://github.com/amphp/http-server.git",
"reference": "b9f6a9e039dd5b9ecc224c6e46d1a410691bbdca" "reference": "33bd2a0c272e16cb51493f0aaabd11c7a9da73ef"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/http-server/zipball/b9f6a9e039dd5b9ecc224c6e46d1a410691bbdca", "url": "https://api.github.com/repos/amphp/http-server/zipball/33bd2a0c272e16cb51493f0aaabd11c7a9da73ef",
"reference": "b9f6a9e039dd5b9ecc224c6e46d1a410691bbdca", "reference": "33bd2a0c272e16cb51493f0aaabd11c7a9da73ef",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -807,7 +805,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-06-03T16:00:02+00:00" "time": "2023-07-31T23:21:23+00:00"
}, },
{ {
"name": "amphp/http-server-form-parser", "name": "amphp/http-server-form-parser",
@ -893,30 +891,33 @@
}, },
{ {
"name": "amphp/http-server-router", "name": "amphp/http-server-router",
"version": "v2.0.0-beta.3", "version": "v2.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/http-server-router.git", "url": "https://github.com/amphp/http-server-router.git",
"reference": "d08be2868ca5e0a0882b6149c3e2546b1e2b3a53" "reference": "8a166efa10bc3fc887a7a42b8a55c7b16bc9fc61"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/http-server-router/zipball/d08be2868ca5e0a0882b6149c3e2546b1e2b3a53", "url": "https://api.github.com/repos/amphp/http-server-router/zipball/8a166efa10bc3fc887a7a42b8a55c7b16bc9fc61",
"reference": "d08be2868ca5e0a0882b6149c3e2546b1e2b3a53", "reference": "8a166efa10bc3fc887a7a42b8a55c7b16bc9fc61",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
"amphp/amp": "^3",
"amphp/cache": "^2", "amphp/cache": "^2",
"amphp/http": "^2-dev", "amphp/http": "^2",
"amphp/http-server": "^3", "amphp/http-server": "^3",
"amphp/socket": "^2", "amphp/socket": "^2",
"nikic/fast-route": "^1", "nikic/fast-route": "^1",
"php": ">=8.1" "php": ">=8.1",
"psr/log": "^1|^2|^3"
}, },
"require-dev": { "require-dev": {
"amphp/log": "^2", "amphp/log": "^2",
"amphp/php-cs-fixer-config": "^2", "amphp/php-cs-fixer-config": "^2",
"amphp/phpunit-util": "^3", "amphp/phpunit-util": "^3",
"colinodell/psr-testlogger": "^1.2",
"league/uri": "^6", "league/uri": "^6",
"phpunit/phpunit": "^9", "phpunit/phpunit": "^9",
"psalm/phar": "^5.6" "psalm/phar": "^5.6"
@ -948,7 +949,7 @@
"email": "aaron@trowski.com" "email": "aaron@trowski.com"
} }
], ],
"description": "Router responder for Amp's HTTP server.", "description": "Routes to request handlers based on HTTP method and path for amphp/http-server.",
"homepage": "https://github.com/amphp/http-server-router", "homepage": "https://github.com/amphp/http-server-router",
"keywords": [ "keywords": [
"http", "http",
@ -957,7 +958,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/amphp/http-server-router/issues", "issues": "https://github.com/amphp/http-server-router/issues",
"source": "https://github.com/amphp/http-server-router/tree/v2.0.0-beta.3" "source": "https://github.com/amphp/http-server-router/tree/v2.0.0"
}, },
"funding": [ "funding": [
{ {
@ -965,20 +966,20 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-04-22T15:05:05+00:00" "time": "2023-08-05T19:16:57+00:00"
}, },
{ {
"name": "amphp/log", "name": "amphp/log",
"version": "v2.0.0-beta.2", "version": "v2.0.0",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/log.git", "url": "https://github.com/amphp/log.git",
"reference": "f65226ffa4dfe0dd63805f2af31aced9ed27efb6" "reference": "bf1562b8a18a3f30efa069ed740f412ac70a8a6c"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/log/zipball/f65226ffa4dfe0dd63805f2af31aced9ed27efb6", "url": "https://api.github.com/repos/amphp/log/zipball/bf1562b8a18a3f30efa069ed740f412ac70a8a6c",
"reference": "f65226ffa4dfe0dd63805f2af31aced9ed27efb6", "reference": "bf1562b8a18a3f30efa069ed740f412ac70a8a6c",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1031,7 +1032,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/amphp/log/issues", "issues": "https://github.com/amphp/log/issues",
"source": "https://github.com/amphp/log/tree/v2.0.0-beta.2" "source": "https://github.com/amphp/log/tree/v2.0.0"
}, },
"funding": [ "funding": [
{ {
@ -1039,7 +1040,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-02-03T03:34:16+00:00" "time": "2023-08-05T18:59:54+00:00"
}, },
{ {
"name": "amphp/mysql", "name": "amphp/mysql",
@ -1397,16 +1398,16 @@
}, },
{ {
"name": "amphp/process", "name": "amphp/process",
"version": "v2.0.0", "version": "v2.0.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/amphp/process.git", "url": "https://github.com/amphp/process.git",
"reference": "9c9247fe8283b22e00a254746bf822da4b0b5ea4" "reference": "a65d3bc1f36ef12d44df42a68f0f0643183f1052"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/amphp/process/zipball/9c9247fe8283b22e00a254746bf822da4b0b5ea4", "url": "https://api.github.com/repos/amphp/process/zipball/a65d3bc1f36ef12d44df42a68f0f0643183f1052",
"reference": "9c9247fe8283b22e00a254746bf822da4b0b5ea4", "reference": "a65d3bc1f36ef12d44df42a68f0f0643183f1052",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -1453,7 +1454,7 @@
"homepage": "https://amphp.org/process", "homepage": "https://amphp.org/process",
"support": { "support": {
"issues": "https://github.com/amphp/process/issues", "issues": "https://github.com/amphp/process/issues",
"source": "https://github.com/amphp/process/tree/v2.0.0" "source": "https://github.com/amphp/process/tree/v2.0.1"
}, },
"funding": [ "funding": [
{ {
@ -1461,7 +1462,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-01-09T21:32:38+00:00" "time": "2023-01-15T16:00:57+00:00"
}, },
{ {
"name": "amphp/redis", "name": "amphp/redis",
@ -2506,12 +2507,12 @@
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/danog/MadelineProto.git", "url": "https://github.com/danog/MadelineProto.git",
"reference": "266370354708e850254e7db76822801026aeee6e" "reference": "28269b1b7631435f42f8be718004f7f0f9ab3f53"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/danog/MadelineProto/zipball/266370354708e850254e7db76822801026aeee6e", "url": "https://api.github.com/repos/danog/MadelineProto/zipball/28269b1b7631435f42f8be718004f7f0f9ab3f53",
"reference": "266370354708e850254e7db76822801026aeee6e", "reference": "28269b1b7631435f42f8be718004f7f0f9ab3f53",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2573,7 +2574,8 @@
"ext-gmp": "Install the gmp extension to speed up authorization", "ext-gmp": "Install the gmp extension to speed up authorization",
"ext-openssl": "Install the openssl extension for faster crypto", "ext-openssl": "Install the openssl extension for faster crypto",
"ext-pdo": "Install the pdo extension to store session data on MySQL", "ext-pdo": "Install the pdo extension to store session data on MySQL",
"ext-primemodule": "Install the primemodule and FFI extensions to speed up MadelineProto (https://prime.madelineproto.xyz)" "ext-primemodule": "Install the primemodule and FFI extensions to speed up MadelineProto (https://prime.madelineproto.xyz)",
"ext-uv": "Install the uv extension to greatly speed up MadelineProto!"
}, },
"default-branch": true, "default-branch": true,
"type": "project", "type": "project",
@ -2619,7 +2621,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/danog/MadelineProto/issues", "issues": "https://github.com/danog/MadelineProto/issues",
"source": "https://github.com/danog/MadelineProto/tree/8.0.0-beta127" "source": "https://github.com/danog/MadelineProto/tree/8.0.0-beta130"
}, },
"funding": [ "funding": [
{ {
@ -2627,7 +2629,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2023-07-27T11:21:21+00:00" "time": "2023-08-07T07:04:07+00:00"
}, },
{ {
"name": "danog/primemodule", "name": "danog/primemodule",
@ -2682,16 +2684,16 @@
}, },
{ {
"name": "danog/tg-file-decoder", "name": "danog/tg-file-decoder",
"version": "0.1.12", "version": "0.1.13",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/danog/tg-file-decoder.git", "url": "https://github.com/danog/tg-file-decoder.git",
"reference": "fd9827e7af8f3b47dc6db4b1c12bfeb6654dde4f" "reference": "5cdb05816aad20583592635eddd90e9c6aae8930"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/danog/tg-file-decoder/zipball/fd9827e7af8f3b47dc6db4b1c12bfeb6654dde4f", "url": "https://api.github.com/repos/danog/tg-file-decoder/zipball/5cdb05816aad20583592635eddd90e9c6aae8930",
"reference": "fd9827e7af8f3b47dc6db4b1c12bfeb6654dde4f", "reference": "5cdb05816aad20583592635eddd90e9c6aae8930",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -2733,7 +2735,7 @@
], ],
"support": { "support": {
"issues": "https://github.com/danog/tg-file-decoder/issues", "issues": "https://github.com/danog/tg-file-decoder/issues",
"source": "https://github.com/danog/tg-file-decoder/tree/0.1.12" "source": "https://github.com/danog/tg-file-decoder/tree/0.1.13"
}, },
"funding": [ "funding": [
{ {
@ -2741,7 +2743,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-11-16T16:22:45+00:00" "time": "2023-08-05T21:04:20+00:00"
}, },
{ {
"name": "dasprid/enum", "name": "dasprid/enum",
@ -3895,16 +3897,16 @@
}, },
{ {
"name": "revolt/event-loop", "name": "revolt/event-loop",
"version": "v1.0.2", "version": "v1.0.3",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/revoltphp/event-loop.git", "url": "https://github.com/revoltphp/event-loop.git",
"reference": "b018d0ff141636d69a8054194675fe0050cf3aa9" "reference": "0fe2d31e1cddd26664e55d383d3d5da613334c03"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://api.github.com/repos/revoltphp/event-loop/zipball/b018d0ff141636d69a8054194675fe0050cf3aa9", "url": "https://api.github.com/repos/revoltphp/event-loop/zipball/0fe2d31e1cddd26664e55d383d3d5da613334c03",
"reference": "b018d0ff141636d69a8054194675fe0050cf3aa9", "reference": "0fe2d31e1cddd26664e55d383d3d5da613334c03",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -3961,9 +3963,9 @@
], ],
"support": { "support": {
"issues": "https://github.com/revoltphp/event-loop/issues", "issues": "https://github.com/revoltphp/event-loop/issues",
"source": "https://github.com/revoltphp/event-loop/tree/v1.0.2" "source": "https://github.com/revoltphp/event-loop/tree/v1.0.3"
}, },
"time": "2023-07-20T20:16:11+00:00" "time": "2023-07-29T17:07:12+00:00"
}, },
{ {
"name": "symfony/polyfill-ctype", "name": "symfony/polyfill-ctype",

View File

@ -11,9 +11,10 @@ use TelegramApiServer\Controllers\ApiController;
use TelegramApiServer\Controllers\EventsController; use TelegramApiServer\Controllers\EventsController;
use TelegramApiServer\Controllers\LogController; use TelegramApiServer\Controllers\LogController;
use TelegramApiServer\Controllers\SystemController; use TelegramApiServer\Controllers\SystemController;
use TelegramApiServer\Logger;
use TelegramApiServer\MadelineProtoExtensions\ApiExtensions; use TelegramApiServer\MadelineProtoExtensions\ApiExtensions;
use TelegramApiServer\MadelineProtoExtensions\SystemApiExtensions; use TelegramApiServer\MadelineProtoExtensions\SystemApiExtensions;
use function Amp\Http\Server\Middleware\stack; use function Amp\Http\Server\Middleware\stackMiddleware;
class Router class Router
{ {
@ -21,7 +22,11 @@ class Router
public function __construct(SocketHttpServer $server, ErrorHandler $errorHandler) public function __construct(SocketHttpServer $server, ErrorHandler $errorHandler)
{ {
$this->router = new \Amp\Http\Server\Router($server, $errorHandler); $this->router = new \Amp\Http\Server\Router(
httpServer: $server,
logger: Logger::getInstance(),
errorHandler: $errorHandler,
);
$this->setRoutes(); $this->setRoutes();
$this->setFallback(); $this->setFallback();
} }
@ -41,10 +46,10 @@ class Router
private function setRoutes(): void private function setRoutes(): void
{ {
$authorization = new Authorization(); $authorization = new Authorization();
$apiHandler = stack(ApiController::getRouterCallback(ApiExtensions::class), $authorization); $apiHandler = stackMiddleware(ApiController::getRouterCallback(ApiExtensions::class), $authorization);
$systemApiHandler = stack(SystemController::getRouterCallback(SystemApiExtensions::class), $authorization); $systemApiHandler = stackMiddleware(SystemController::getRouterCallback(SystemApiExtensions::class), $authorization);
$eventsHandler = stack(EventsController::getRouterCallback(), $authorization); $eventsHandler = stackMiddleware(EventsController::getRouterCallback(), $authorization);
$logHandler = stack(LogController::getRouterCallback(), $authorization); $logHandler = stackMiddleware(LogController::getRouterCallback(), $authorization);
foreach (['GET', 'POST'] as $method) { foreach (['GET', 'POST'] as $method) {
$this->router->addRoute($method, '/api/{method}[/]', $apiHandler); $this->router->addRoute($method, '/api/{method}[/]', $apiHandler);