From 2d968c3623277aa708e888382c93b02dc54035d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Tue, 19 Oct 2021 17:32:26 +0800 Subject: [PATCH] =?UTF-8?q?=E6=94=B9=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- http-handler/CoreMiddleware.php | 18 ++++++++++++++---- http-server/Abstracts/OnTaskerStart.php | 10 ++++++++-- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/http-handler/CoreMiddleware.php b/http-handler/CoreMiddleware.php index a6443656..e0aabd1c 100644 --- a/http-handler/CoreMiddleware.php +++ b/http-handler/CoreMiddleware.php @@ -2,12 +2,17 @@ namespace Http\Handler; +use Exception; use Http\Handler\Abstracts\Middleware; use Http\Message\ServerRequest; use Psr\Http\Message\ResponseInterface; use Psr\Http\Message\ServerRequestInterface; use Psr\Http\Server\RequestHandlerInterface; + +/** + * + */ class CoreMiddleware extends Middleware { @@ -16,14 +21,19 @@ class CoreMiddleware extends Middleware * @param ServerRequest $request * @param RequestHandlerInterface $handler * @return ResponseInterface - * @throws \Exception + * @throws Exception */ public function process(ServerRequestInterface $request, RequestHandlerInterface $handler): ResponseInterface { - $this->response->withAccessControlAllowOrigin('*') - ->withAccessControlRequestMethod($request->getAccessControlRequestMethod()) - ->withAccessControlAllowHeaders($request->getAccessControlAllowHeaders()); + $requestMethod = $request->getAccessControlRequestMethod(); + $allowHeaders = $request->getAccessControlAllowHeaders(); + + if (empty($requestMethod)) $requestMethod = '*'; + if (empty($allowHeaders)) $allowHeaders = '*'; + + $this->response->withAccessControlAllowOrigin('*')->withAccessControlRequestMethod($requestMethod) + ->withAccessControlAllowHeaders($allowHeaders); return $handler->handle($request); } diff --git a/http-server/Abstracts/OnTaskerStart.php b/http-server/Abstracts/OnTaskerStart.php index b3c6a161..1a82ca6b 100644 --- a/http-server/Abstracts/OnTaskerStart.php +++ b/http-server/Abstracts/OnTaskerStart.php @@ -2,17 +2,23 @@ namespace Server\Abstracts; +use Kiri\Exception\ConfigException; use Kiri\Kiri; use Psr\EventDispatcher\EventDispatcherInterface; +use ReflectionException; use Server\ServerManager; + +/** + * + */ class OnTaskerStart extends WorkerStart implements EventDispatcherInterface { /** - * @throws \Kiri\Exception\ConfigException - * @throws \ReflectionException + * @throws ConfigException + * @throws ReflectionException */ public function dispatch(object $event) {