From c12606d233f57dde7fb05efb87011987cf34396e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=90=91=E6=9E=97?= Date: Wed, 19 Apr 2023 23:51:39 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8F=98=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Base/CoreMiddleware.php | 11 +++++------ src/Constrict/Message.php | 11 +++++++++++ src/Response.php | 10 ++++++++++ 3 files changed, 26 insertions(+), 6 deletions(-) diff --git a/src/Base/CoreMiddleware.php b/src/Base/CoreMiddleware.php index 8d9bc1a..10f1071 100644 --- a/src/Base/CoreMiddleware.php +++ b/src/Base/CoreMiddleware.php @@ -28,12 +28,11 @@ class CoreMiddleware implements MiddlewareInterface { /** @var ResponseInterface $response */ $response = \Kiri::service()->get('response'); -// $response->withHeader('Access-Control-Allow-Headers', $request->header('Access-Control-Allow-Headers')) -// ->withHeader('Access-Control-Request-Method', $request->header('Access-Control-Allow-Origin')) -// ->withHeader('Access-Control-Allow-Origin', $request->header('Access-Control-Allow-Headers')); - $response->withHeader('Access-Control-Allow-Headers', '*') - ->withHeader('Access-Control-Request-Method', '*') - ->withHeader('Access-Control-Allow-Origin', '*'); + $response->withHeaders([ + 'Access-Control-Allow-Headers' => '*', + 'Access-Control-Request-Method' => '*', + 'Access-Control-Allow-Origin' => '*' + ]); return $handler->handle($request); } diff --git a/src/Constrict/Message.php b/src/Constrict/Message.php index 9d9cfd3..0641e6b 100644 --- a/src/Constrict/Message.php +++ b/src/Constrict/Message.php @@ -251,6 +251,17 @@ class Message extends Component implements MessageInterface return $this; } + + /** + * @param array $headers + * @return $this + */ + public function withHeaders(array $headers): static + { + $this->headers = $headers; + return $this; + } + /** * Return an instance with the specified header appended with the given value. * diff --git a/src/Response.php b/src/Response.php index 5d9b501..2de7751 100644 --- a/src/Response.php +++ b/src/Response.php @@ -263,6 +263,16 @@ class Response implements ResponseInterface return $this->__call__(__FUNCTION__, $name, $value); } + + /** + * @param array $headers + * @return ResponseInterface + */ + public function withHeaders(array $headers): ResponseInterface + { + return $this->__call__(__FUNCTION__, $headers); + } + /** * Return an instance with the specified header appended with the given value. *