mirror of
https://github.com/appwrite/appwrite.git
synced 2026-05-26 13:51:13 +00:00
Add execution id and log id to response headers
This commit is contained in:
@@ -610,6 +610,12 @@ function router(App $utopia, Database $dbForPlatform, callable $getProjectDB, Sw
|
||||
}
|
||||
}
|
||||
|
||||
if ($deployment->getAttribute('resourceType') === 'functions') {
|
||||
$executionResponse['headers']['x-appwrite-execution-id'] = $execution->getId();
|
||||
} elseif ($deployment->getAttribute('resourceType') === 'sites') {
|
||||
$executionResponse['headers']['x-appwrite-log-id'] = $execution->getId();
|
||||
}
|
||||
|
||||
$headersFiltered = [];
|
||||
foreach ($executionResponse['headers'] as $key => $value) {
|
||||
if (\in_array(\strtolower($key), FUNCTION_ALLOWLIST_HEADERS_RESPONSE)) {
|
||||
|
||||
@@ -147,7 +147,7 @@ const APP_FUNCTION_LOG_LENGTH_LIMIT = 1000000;
|
||||
const APP_FUNCTION_ERROR_LENGTH_LIMIT = 1000000;
|
||||
// Function headers
|
||||
const FUNCTION_ALLOWLIST_HEADERS_REQUEST = ['content-type', 'agent', 'content-length', 'host'];
|
||||
const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length'];
|
||||
const FUNCTION_ALLOWLIST_HEADERS_RESPONSE = ['content-type', 'content-length', 'x-appwrite-execution-id', 'x-appwrite-log-id'];
|
||||
// Message types
|
||||
const MESSAGE_TYPE_EMAIL = 'email';
|
||||
const MESSAGE_TYPE_SMS = 'sms';
|
||||
|
||||
@@ -486,6 +486,8 @@ class Create extends Base
|
||||
$headers[] = ['name' => $key, 'value' => $value];
|
||||
}
|
||||
|
||||
$headers[] = ['name' => 'x-appwrite-execution-id', 'value' => $execution->getId()];
|
||||
|
||||
$execution->setAttribute('responseBody', $executionResponse['body'] ?? '');
|
||||
$execution->setAttribute('responseHeaders', $headers);
|
||||
|
||||
|
||||
@@ -549,6 +549,7 @@ class Functions extends Action
|
||||
$headersFiltered[] = [ 'name' => $key, 'value' => $value ];
|
||||
}
|
||||
}
|
||||
$headersFiltered[] = ['name' => 'x-appwrite-execution-id', 'value' => $execution->getId()];
|
||||
|
||||
$maxLogLength = APP_FUNCTION_LOG_LENGTH_LIMIT;
|
||||
$logs = $executionResponse['logs'] ?? '';
|
||||
|
||||
@@ -142,6 +142,19 @@ class FunctionsCustomClientTest extends Scope
|
||||
]);
|
||||
$output = json_decode($execution['body']['responseBody'], true);
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
|
||||
$this->assertNotEmpty($execution['body']['responseHeaders']);
|
||||
|
||||
$executionIdHeader = null;
|
||||
foreach ($execution['body']['responseHeaders'] as $header) {
|
||||
if ($header['name'] === 'x-appwrite-execution-id') {
|
||||
$executionIdHeader = $header['value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertNotEmpty($executionIdHeader);
|
||||
$this->assertEquals($execution['body']['$id'], $executionIdHeader);
|
||||
|
||||
$this->assertEquals(200, $execution['body']['responseStatusCode']);
|
||||
$this->assertGreaterThan(0, $execution['body']['duration']);
|
||||
$this->assertEquals('completed', $execution['body']['status']);
|
||||
|
||||
@@ -892,6 +892,19 @@ class FunctionsCustomServerTest extends Scope
|
||||
]);
|
||||
|
||||
$this->assertEquals(201, $execution['headers']['status-code']);
|
||||
|
||||
$this->assertNotEmpty($execution['body']['responseHeaders']);
|
||||
|
||||
$executionIdHeader = null;
|
||||
foreach ($execution['body']['responseHeaders'] as $header) {
|
||||
if ($header['name'] === 'x-appwrite-execution-id') {
|
||||
$executionIdHeader = $header['value'];
|
||||
break;
|
||||
}
|
||||
}
|
||||
$this->assertNotEmpty($executionIdHeader);
|
||||
$this->assertEquals($execution['body']['$id'], $executionIdHeader);
|
||||
|
||||
$this->assertNotEmpty($execution['body']['$id']);
|
||||
$this->assertNotEmpty($execution['body']['functionId']);
|
||||
$this->assertEquals(true, (new DatetimeValidator())->isValid($execution['body']['$createdAt']));
|
||||
|
||||
@@ -1433,6 +1433,9 @@ class SitesCustomServerTest extends Scope
|
||||
$this->assertEquals(200, $response['headers']['status-code']);
|
||||
$this->assertStringContainsString("Index page", $response['body']);
|
||||
|
||||
$this->assertArrayHasKey('x-appwrite-log-id', $response['headers']);
|
||||
$this->assertNotEmpty($response['headers']['x-appwrite-log-id']);
|
||||
|
||||
$response = $proxyClient->call(Client::METHOD_GET, '/contact', array_merge([
|
||||
'content-type' => 'application/json',
|
||||
'x-appwrite-project' => $this->getProject()['$id'],
|
||||
|
||||
Reference in New Issue
Block a user