This commit is contained in:
2023-04-16 03:27:43 +08:00
parent 4b6c8dd699
commit d32768064a
4 changed files with 48 additions and 6 deletions
+23
View File
@@ -14,6 +14,7 @@ class ConstrictResponse extends Message implements ResponseInterface
private string $reasonPhrase;
private array $cookieParams;
/**
@@ -88,6 +89,28 @@ class ConstrictResponse extends Message implements ResponseInterface
}
/**
* @param array $cookies
* @return ResponseInterface
*/
public function withCookieParams(array $cookies): static
{
$this->cookieParams = $cookies;
return $this;
}
/**
* @return array
*/
public function getCookieParams(): array
{
return $this->cookieParams;
}
/**
* @param object $response
* @return void
+1 -4
View File
@@ -41,10 +41,7 @@ class HttpResponseEmitter implements ResponseEmitter
foreach ($resp->getHeaders() as $name => $header) {
$response->header($name, implode(', ', $header));
}
/** @var Request $request */
$request = \Kiri::service()->get('request');
foreach ($request->getCookieParams() as $cookie) {
foreach ($resp->getCookieParams() as $cookie) {
$response->setCookie(...$cookie);
}
$response->header('Server', 'swoole');
+19
View File
@@ -45,6 +45,25 @@ class Response implements ResponseInterface
}
/**
* @param array $cookies
* @return ResponseInterface
*/
public function withCookieParams(array $cookies): ResponseInterface
{
return $this->__call__(__FUNCTION__, $cookies);
}
/**
* @return array
*/
public function getCookieParams(): array
{
return $this->__call__(__FUNCTION__);
}
/**
* Retrieves the HTTP protocol version as a string.
*
+5 -2
View File
@@ -109,14 +109,17 @@ class Server implements OnRequestInterface
/** @var \Kiri\Router\Response $response */
$response = Kiri::service()->get('response');
$cookie = $request->cookie ?? [];
/** @var ConstrictResponse $PsrResponse */
$PsrResponse = Context::set(ResponseInterface::class, new ConstrictResponse());
$PsrResponse->withContentType($response->contentType);
$PsrResponse->withContentType($response->contentType)->withCookieParams($cookie);
$serverRequest = (new ConstrictRequest())->withDataHeaders($request->getData())
->withUri(Uri::parse($request))
->withProtocolVersion($request->server['server_protocol'])
->withCookieParams($request->cookie ?? [])
->withCookieParams($cookie)
->withQueryParams($request->get ?? [])
->withUploadedFiles($request->files ?? [])
->withMethod($request->getMethod())