mirror of
https://github.com/appwrite/appwrite
synced 2026-05-24 01:18:37 +00:00
Add request headers
This commit is contained in:
parent
eb8543c690
commit
ec930bf125
1 changed files with 19 additions and 2 deletions
|
|
@ -200,6 +200,8 @@ class Functions extends Action
|
||||||
* @param string $path
|
* @param string $path
|
||||||
* @param string $method
|
* @param string $method
|
||||||
* @param Document $user
|
* @param Document $user
|
||||||
|
* @param string|null $jwt
|
||||||
|
* @param string|null $event
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
*/
|
*/
|
||||||
private function fail(
|
private function fail(
|
||||||
|
|
@ -209,7 +211,21 @@ class Functions extends Action
|
||||||
string $path,
|
string $path,
|
||||||
string $method,
|
string $method,
|
||||||
Document $user,
|
Document $user,
|
||||||
|
string $jwt = null,
|
||||||
|
string $event = null,
|
||||||
): void {
|
): void {
|
||||||
|
$headers['x-appwrite-trigger'] = $trigger;
|
||||||
|
$headers['x-appwrite-event'] = $event ?? '';
|
||||||
|
$headers['x-appwrite-user-id'] = $user->getId() ?? '';
|
||||||
|
$headers['x-appwrite-user-jwt'] = $jwt ?? '';
|
||||||
|
|
||||||
|
$headersFiltered = [];
|
||||||
|
foreach ($headers as $key => $value) {
|
||||||
|
if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_REQUEST)) {
|
||||||
|
$headersFiltered[] = ['name' => $key, 'value' => $value];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$executionId = ID::unique();
|
$executionId = ID::unique();
|
||||||
$execution = new Document([
|
$execution = new Document([
|
||||||
'$id' => $executionId,
|
'$id' => $executionId,
|
||||||
|
|
@ -224,6 +240,7 @@ class Functions extends Action
|
||||||
'responseHeaders' => [],
|
'responseHeaders' => [],
|
||||||
'requestPath' => $path,
|
'requestPath' => $path,
|
||||||
'requestMethod' => $method,
|
'requestMethod' => $method,
|
||||||
|
'requestHeaders' => $headersFiltered,
|
||||||
'errors' => 'Deployment not found. Create deployment before trying to execute a function.',
|
'errors' => 'Deployment not found. Create deployment before trying to execute a function.',
|
||||||
'logs' => '',
|
'logs' => '',
|
||||||
'duration' => 0.0,
|
'duration' => 0.0,
|
||||||
|
|
@ -293,12 +310,12 @@ class Functions extends Action
|
||||||
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
$deployment = $dbForProject->getDocument('deployments', $deploymentId);
|
||||||
|
|
||||||
if ($deployment->getAttribute('resourceId') !== $functionId) {
|
if ($deployment->getAttribute('resourceId') !== $functionId) {
|
||||||
$this->fail($dbForProject, $function, $trigger, $path, $method, $user);
|
$this->fail($dbForProject, $function, $trigger, $path, $method, $user, $jwt, $event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if ($deployment->isEmpty()) {
|
if ($deployment->isEmpty()) {
|
||||||
$this->fail($dbForProject, $function, $trigger, $path, $method, $user);
|
$this->fail($dbForProject, $function, $trigger, $path, $method, $user, $jwt, $event);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue