This commit is contained in:
2023-04-19 23:51:39 +08:00
parent 994e6e7301
commit c12606d233
3 changed files with 26 additions and 6 deletions
+5 -6
View File
@@ -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);
}
+11
View File
@@ -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.
*
+10
View File
@@ -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.
*