mirror of
https://github.com/appwrite/appwrite.git
synced 2026-11-18 20:36:03 +00:00
fix(http): restore synthesized cookie header for request forwarding
SitesCustomServerTest::testCookieHeader regressed: removing the custom Request::getHeaders() override dropped cookie forwarding to function/site executions. Swoole parses the incoming Cookie header into its own cookie jar, so it is absent from the raw header map — the synthesized `cookie` header was load-bearing, not dead code (the allowlist only filters the stored execution metadata, while the full header map is what reaches the executor). Restore the override in PSR-7 form, rebuilding the header from rc5's getCookieParams(), and add unit tests covering the behavior. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
4870e2eb50
commit
47e30bda63
2 files changed
+50
No files matched your search
@@ -177,6 +177,32 @@ class Request extends UtopiaRequest
|
||||
return $this->route !== null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get headers
|
||||
*
|
||||
* Method for getting all HTTP headers, including a synthesized `cookie`
|
||||
* header. Swoole parses the incoming Cookie header into its own cookie jar,
|
||||
* so it is absent from the raw header map; rebuild it here so consumers that
|
||||
* forward request headers (e.g. function/site executions) still receive it.
|
||||
*
|
||||
* @return array<string, array<int, string>>
|
||||
*/
|
||||
public function getHeaders(): array
|
||||
{
|
||||
$headers = parent::getHeaders();
|
||||
|
||||
$cookies = $this->getCookieParams();
|
||||
if (!empty($cookies)) {
|
||||
$pairs = [];
|
||||
foreach ($cookies as $key => $value) {
|
||||
$pairs[] = "{$key}={$value}";
|
||||
}
|
||||
$headers['cookie'] = [\implode('; ', $pairs)];
|
||||
}
|
||||
|
||||
return $headers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get User Agent
|
||||
*
|
||||
|
||||
@@ -187,6 +187,30 @@ final class RequestTest extends TestCase
|
||||
$this->assertSame('https://a.example, https://b.example', $request->getHeaderLine('referer'));
|
||||
}
|
||||
|
||||
public function testGetHeadersSynthesizesCookieHeaderFromCookieJar(): void
|
||||
{
|
||||
// Swoole parses the Cookie header into its cookie jar, so getHeaders()
|
||||
// must rebuild it for consumers that forward request headers onward
|
||||
// (e.g. function/site executions).
|
||||
$swoole = new SwooleRequest();
|
||||
$swoole->header = ['host' => 'example.com'];
|
||||
$swoole->cookie = ['custom-session-id' => 'abcd123', 'custom-user-id' => 'efgh456'];
|
||||
$request = new Request($swoole);
|
||||
|
||||
$headers = $request->getHeaders();
|
||||
|
||||
$this->assertSame(['custom-session-id=abcd123; custom-user-id=efgh456'], $headers['cookie']);
|
||||
}
|
||||
|
||||
public function testGetHeadersOmitsCookieHeaderWhenNoCookies(): void
|
||||
{
|
||||
$swoole = new SwooleRequest();
|
||||
$swoole->header = ['host' => 'example.com'];
|
||||
$request = new Request($swoole);
|
||||
|
||||
$this->assertArrayNotHasKey('cookie', $request->getHeaders());
|
||||
}
|
||||
|
||||
public function testGetParamsCachesRawParamsWhenFilterThrows4xx(): void
|
||||
{
|
||||
/*
|
||||
|
||||
Reference in new issue
Block a user