diff --git a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php index c54b1d7303..3967b20e49 100644 --- a/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php +++ b/src/Appwrite/Platform/Modules/Functions/Http/Executions/Create.php @@ -481,13 +481,13 @@ class Create extends Base $execution = Authorization::skip(fn () => $dbForProject->createDocument('executions', $execution)); } + $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + $headers = []; foreach (($executionResponse['headers'] ?? []) as $key => $value) { $headers[] = ['name' => $key, 'value' => $value]; } - $headers[] = ['name' => 'x-appwrite-execution-id', 'value' => $execution->getId()]; - $execution->setAttribute('responseBody', $executionResponse['body'] ?? ''); $execution->setAttribute('responseHeaders', $headers); diff --git a/src/Appwrite/Platform/Workers/Functions.php b/src/Appwrite/Platform/Workers/Functions.php index 295c02061f..af91019f2e 100644 --- a/src/Appwrite/Platform/Workers/Functions.php +++ b/src/Appwrite/Platform/Workers/Functions.php @@ -543,13 +543,14 @@ class Functions extends Action $status = $executionResponse['statusCode'] >= 500 ? 'failed' : 'completed'; + $executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId(); + $headersFiltered = []; foreach ($executionResponse['headers'] as $key => $value) { if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_RESPONSE)) { $headersFiltered[] = [ 'name' => $key, 'value' => $value ]; } } - $headersFiltered[] = ['name' => 'x-appwrite-execution-id', 'value' => $execution->getId()]; $maxLogLength = APP_FUNCTION_LOG_LENGTH_LIMIT; $logs = $executionResponse['logs'] ?? ''; diff --git a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php index ad14990c2b..95781f0390 100644 --- a/tests/e2e/Services/Functions/FunctionsCustomServerTest.php +++ b/tests/e2e/Services/Functions/FunctionsCustomServerTest.php @@ -1689,6 +1689,9 @@ class FunctionsCustomServerTest extends Scope $this->assertEquals(200, $response['headers']['status-code']); $this->assertEquals($cookie, $response['body']); + $this->assertArrayHasKey('x-appwrite-execution-id', $response['headers']); + $this->assertNotEmpty($response['headers']['x-appwrite-execution-id']); + // Async execution document creation $this->assertEventually(function () use ($functionId) { $executions = $this->client->call(Client::METHOD_GET, '/functions/' . $functionId . '/executions', array_merge([