mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Move cookie-header logic to request
This commit is contained in:
@@ -95,4 +95,42 @@ class Request extends UtopiaRequest
|
||||
{
|
||||
return self::$route != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers
|
||||
*
|
||||
* Method for getting all HTTP header parameters, including cookies.
|
||||
*
|
||||
* @return array<string,mixed>
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
$headers = $this->generateHeaders();
|
||||
|
||||
$cookieHeaders = [];
|
||||
foreach ($this->swoole->cookie as $key => $value) {
|
||||
$cookieHeaders[] = "{$key}={$value}";
|
||||
}
|
||||
|
||||
if (!empty($cookieHeaders)) {
|
||||
$headers['cookie'] = \implode('; ', $cookieHeaders);
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get header
|
||||
*
|
||||
* Method for querying HTTP header parameters. If $key is not found $default value will be returned.
|
||||
*
|
||||
* @param string $key
|
||||
* @param string $default
|
||||
* @return string
|
||||
*/
|
||||
public function getHeader(string $key, string $default = ''): string
|
||||
{
|
||||
$headers = $this->getHeaders();
|
||||
return $headers[$key] ?? $default;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user