diff --git a/.env b/.env index f6a6a7f642..8ff8164a21 100644 --- a/.env +++ b/.env @@ -2,6 +2,7 @@ _APP_ENV=development _APP_EDITION=self-hosted _APP_LOCALE=en _APP_WORKER_PER_CORE=6 +_APP_COMPRESSION_MIN_SIZE_BYTES=1024 _APP_CONSOLE_WHITELIST_ROOT=disabled _APP_CONSOLE_WHITELIST_EMAILS= _APP_CONSOLE_SESSION_ALERTS=enabled diff --git a/Dockerfile b/Dockerfile index 13b018df0f..07295f4afb 100755 --- a/Dockerfile +++ b/Dockerfile @@ -92,10 +92,10 @@ RUN chmod +x /usr/local/bin/doctor && \ RUN mkdir -p /etc/letsencrypt/live/ && chmod -Rf 755 /etc/letsencrypt/live/ # Enable Extensions -RUN if [ "$DEBUG" == "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi -RUN if [ "$DEBUG" == "true" ]; then mkdir -p /tmp/xdebug; fi +RUN if [ "$DEBUG" = "true" ]; then cp /usr/src/code/dev/xdebug.ini /usr/local/etc/php/conf.d/xdebug.ini; fi +RUN if [ "$DEBUG" = "true" ]; then mkdir -p /tmp/xdebug; fi RUN if [ "$DEBUG" = "false" ]; then rm -rf /usr/src/code/dev; fi -RUN if [ "$DEBUG" = "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20220829/xdebug.so; fi +RUN if [ "$DEBUG" = "false" ]; then rm -f /usr/local/lib/php/extensions/no-debug-non-zts-20230831/xdebug.so; fi EXPOSE 80 diff --git a/app/controllers/api/functions.php b/app/controllers/api/functions.php index 0ca73ee6ac..2309defe5a 100644 --- a/app/controllers/api/functions.php +++ b/app/controllers/api/functions.php @@ -326,9 +326,9 @@ App::post('/v1/functions') $functionsDomain = System::getEnv('_APP_DOMAIN_FUNCTIONS', ''); if (!empty($functionsDomain)) { - $ruleId = ID::unique(); $routeSubdomain = ID::unique(); $domain = "{$routeSubdomain}.{$functionsDomain}"; + $ruleId = md5($domain); $rule = Authorization::skip( fn () => $dbForConsole->createDocument('rules', new Document([ diff --git a/app/controllers/api/proxy.php b/app/controllers/api/proxy.php index 02a3ec8e9d..56fd31e88c 100644 --- a/app/controllers/api/proxy.php +++ b/app/controllers/api/proxy.php @@ -11,7 +11,6 @@ use Utopia\App; use Utopia\Database\Database; use Utopia\Database\Document; use Utopia\Database\Exception\Query as QueryException; -use Utopia\Database\Helpers\ID; use Utopia\Database\Query; use Utopia\Database\Validator\Query\Cursor; use Utopia\Database\Validator\UID; @@ -60,9 +59,8 @@ App::post('/v1/proxy/rules') throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'This domain name is not allowed. Please pick another one.'); } - $document = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain]), - ]); + $ruleId = md5($domain); + $document = $dbForConsole->getDocument('rules', $ruleId); if (!$document->isEmpty()) { if ($document->getAttribute('projectId') === $project->getId()) { @@ -103,7 +101,7 @@ App::post('/v1/proxy/rules') throw new Exception(Exception::GENERAL_ARGUMENT_INVALID, 'Domain may not start with http:// or https://.'); } - $ruleId = ID::unique(); + $ruleId = md5($domain->get()); $rule = new Document([ '$id' => $ruleId, 'projectId' => $project->getId(), diff --git a/app/controllers/general.php b/app/controllers/general.php index b08ecb3d12..663242882a 100644 --- a/app/controllers/general.php +++ b/app/controllers/general.php @@ -29,7 +29,6 @@ use Utopia\Database\Database; use Utopia\Database\DateTime; use Utopia\Database\Document; use Utopia\Database\Helpers\ID; -use Utopia\Database\Query; use Utopia\Database\Validator\Authorization; use Utopia\Domains\Domain; use Utopia\DSN\DSN; @@ -52,14 +51,9 @@ function router(App $utopia, Database $dbForConsole, callable $getProjectDB, Swo $host = $request->getHostname() ?? ''; - $route = Authorization::skip( - fn () => $dbForConsole->find('rules', [ - Query::equal('domain', [$host]), - Query::limit(1) - ]) - )[0] ?? null; + $route = Authorization::skip(fn () => $dbForConsole->getDocument('rules', md5($host))); - if ($route === null) { + if ($route->isEmpty()) { if ($host === System::getEnv('_APP_DOMAIN_FUNCTIONS', '')) { throw new AppwriteException(AppwriteException::GENERAL_ACCESS_FORBIDDEN, 'This domain cannot be used for security reasons. Please use any subdomain instead.'); } @@ -518,19 +512,18 @@ App::init() if (!empty($envDomain) && $envDomain !== 'localhost') { $mainDomain = $envDomain; } else { - $domainDocument = $dbForConsole->findOne('rules', [Query::orderAsc('$id')]); + $domainDocument = $dbForConsole->getDocument('rules', md5($envDomain)); $mainDomain = !$domainDocument->isEmpty() ? $domainDocument->getAttribute('domain') : $domain->get(); } if ($mainDomain !== $domain->get()) { Console::warning($domain->get() . ' is not a main domain. Skipping SSL certificate generation.'); } else { - $domainDocument = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain->get()]) - ]); + $domainDocument = $dbForConsole->getDocument('rules', md5($domain->get())); if ($domainDocument->isEmpty()) { $domainDocument = new Document([ + '$id' => md5($domain->get()), 'domain' => $domain->get(), 'resourceType' => 'api', 'status' => 'verifying', diff --git a/app/http.php b/app/http.php index 9754263046..41f6283156 100644 --- a/app/http.php +++ b/app/http.php @@ -40,8 +40,7 @@ $http ->set([ 'worker_num' => $workerNumber, 'open_http2_protocol' => true, - 'http_compression' => true, - 'http_compression_level' => 6, + 'http_compression' => false, 'package_max_length' => $payloadSize, 'buffer_output_size' => $payloadSize, ]); @@ -62,6 +61,8 @@ include __DIR__ . '/controllers/general.php'; $http->on(Constant::EVENT_START, function (Server $http) use ($payloadSize, $register) { $app = new App('UTC'); + $app->setCompression(true); + $app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB go(function () use ($register, $app) { $pools = $register->get('pools'); @@ -245,6 +246,8 @@ $http->on(Constant::EVENT_REQUEST, function (SwooleRequest $swooleRequest, Swool } $app = new App('UTC'); + $app->setCompression(true); + $app->setCompressionMinSize(intval(System::getEnv('_APP_COMPRESSION_MIN_SIZE_BYTES', '1024'))); // 1KB $pools = $register->get('pools'); App::setResource('pools', fn () => $pools); diff --git a/app/views/install/compose.phtml b/app/views/install/compose.phtml index ad35135a6f..8d7fecb479 100644 --- a/app/views/install/compose.phtml +++ b/app/views/install/compose.phtml @@ -73,6 +73,7 @@ $image = $this->getParam('image', ''); - _APP_ENV - _APP_WORKER_PER_CORE - _APP_LOCALE + - _APP_COMPRESSION_MIN_SIZE_BYTES - _APP_CONSOLE_WHITELIST_ROOT - _APP_CONSOLE_WHITELIST_EMAILS - _APP_CONSOLE_SESSION_ALERTS diff --git a/composer.lock b/composer.lock index 182724a85e..14a3a7ee36 100644 --- a/composer.lock +++ b/composer.lock @@ -1671,6 +1671,52 @@ }, "time": "2024-10-04T13:55:36+00:00" }, + { + "name": "utopia-php/compression", + "version": "0.1.2", + "source": { + "type": "git", + "url": "https://github.com/utopia-php/compression.git", + "reference": "6062f70596415f8d5de40a589367b0eb2a435f98" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/utopia-php/compression/zipball/6062f70596415f8d5de40a589367b0eb2a435f98", + "reference": "6062f70596415f8d5de40a589367b0eb2a435f98", + "shasum": "" + }, + "require": { + "php": ">=8.0" + }, + "require-dev": { + "laravel/pint": "1.2.*", + "phpunit/phpunit": "^9.3", + "vimeo/psalm": "4.0.1" + }, + "type": "library", + "autoload": { + "psr-4": { + "Utopia\\Compression\\": "src/Compression" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A simple Compression library to handle file compression", + "keywords": [ + "compression", + "framework", + "php", + "upf", + "utopia" + ], + "support": { + "issues": "https://github.com/utopia-php/compression/issues", + "source": "https://github.com/utopia-php/compression/tree/0.1.2" + }, + "time": "2024-11-08T14:59:54+00:00" + }, { "name": "utopia-php/config", "version": "0.2.2", @@ -1926,20 +1972,21 @@ }, { "name": "utopia-php/framework", - "version": "0.33.8", + "version": "0.33.11", "source": { "type": "git", "url": "https://github.com/utopia-php/http.git", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5" + "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/utopia-php/http/zipball/a7f577540a25cb90896fef2b64767bf8d700f3c5", - "reference": "a7f577540a25cb90896fef2b64767bf8d700f3c5", + "url": "https://api.github.com/repos/utopia-php/http/zipball/354ff0d23bfc6e82bea0fe8e89e115cff1af8466", + "reference": "354ff0d23bfc6e82bea0fe8e89e115cff1af8466", "shasum": "" }, "require": { - "php": ">=8.0" + "php": ">=8.0", + "utopia-php/compression": "0.1.*" }, "require-dev": { "laravel/pint": "^1.2", @@ -1965,9 +2012,9 @@ ], "support": { "issues": "https://github.com/utopia-php/http/issues", - "source": "https://github.com/utopia-php/http/tree/0.33.8" + "source": "https://github.com/utopia-php/http/tree/0.33.11" }, - "time": "2024-08-15T14:10:09+00:00" + "time": "2024-11-08T18:47:43+00:00" }, { "name": "utopia-php/image", @@ -3513,16 +3560,16 @@ }, { "name": "myclabs/deep-copy", - "version": "1.12.0", + "version": "1.12.1", "source": { "type": "git", "url": "https://github.com/myclabs/DeepCopy.git", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c" + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", - "reference": "3a6b9a42cd8f8771bd4295d13e1423fa7f3d942c", + "url": "https://api.github.com/repos/myclabs/DeepCopy/zipball/123267b2c49fbf30d78a7b2d333f6be754b94845", + "reference": "123267b2c49fbf30d78a7b2d333f6be754b94845", "shasum": "" }, "require": { @@ -3561,7 +3608,7 @@ ], "support": { "issues": "https://github.com/myclabs/DeepCopy/issues", - "source": "https://github.com/myclabs/DeepCopy/tree/1.12.0" + "source": "https://github.com/myclabs/DeepCopy/tree/1.12.1" }, "funding": [ { @@ -3569,7 +3616,7 @@ "type": "tidelift" } ], - "time": "2024-06-12T14:39:25+00:00" + "time": "2024-11-08T17:47:46+00:00" }, { "name": "nikic/php-parser", @@ -4068,23 +4115,23 @@ }, { "name": "phpdocumentor/type-resolver", - "version": "1.9.0", + "version": "1.10.0", "source": { "type": "git", "url": "https://github.com/phpDocumentor/TypeResolver.git", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d" + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/1fb5ba8d045f5dd984ebded5b1cc66f29459422d", - "reference": "1fb5ba8d045f5dd984ebded5b1cc66f29459422d", + "url": "https://api.github.com/repos/phpDocumentor/TypeResolver/zipball/679e3ce485b99e84c775d28e2e96fade9a7fb50a", + "reference": "679e3ce485b99e84c775d28e2e96fade9a7fb50a", "shasum": "" }, "require": { "doctrine/deprecations": "^1.0", "php": "^7.3 || ^8.0", "phpdocumentor/reflection-common": "^2.0", - "phpstan/phpdoc-parser": "^1.18" + "phpstan/phpdoc-parser": "^1.18|^2.0" }, "require-dev": { "ext-tokenizer": "*", @@ -4120,9 +4167,9 @@ "description": "A PSR-5 based resolver of Class names, Types and Structural Element Names", "support": { "issues": "https://github.com/phpDocumentor/TypeResolver/issues", - "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.9.0" + "source": "https://github.com/phpDocumentor/TypeResolver/tree/1.10.0" }, - "time": "2024-11-03T20:11:34+00:00" + "time": "2024-11-09T15:12:26+00:00" }, { "name": "phpspec/prophecy", diff --git a/docker-compose.yml b/docker-compose.yml index 6364ef2c63..0f3f05847c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -96,6 +96,7 @@ services: - _APP_EDITION - _APP_WORKER_PER_CORE - _APP_LOCALE + - _APP_COMPRESSION_MIN_SIZE_BYTES - _APP_CONSOLE_WHITELIST_ROOT - _APP_CONSOLE_WHITELIST_EMAILS - _APP_CONSOLE_SESSION_ALERTS diff --git a/src/Appwrite/Event/Audit.php b/src/Appwrite/Event/Audit.php index 4b02849970..17506bfe6c 100644 --- a/src/Appwrite/Event/Audit.php +++ b/src/Appwrite/Event/Audit.php @@ -121,6 +121,10 @@ class Audit extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Build.php b/src/Appwrite/Event/Build.php index b8cb62a6f8..1fbf20a9f9 100644 --- a/src/Appwrite/Event/Build.php +++ b/src/Appwrite/Event/Build.php @@ -112,6 +112,10 @@ class Build extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Certificate.php b/src/Appwrite/Event/Certificate.php index 85058c96fe..5d30c3d5ac 100644 --- a/src/Appwrite/Event/Certificate.php +++ b/src/Appwrite/Event/Certificate.php @@ -74,6 +74,10 @@ class Certificate extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Database.php b/src/Appwrite/Event/Database.php index f9eb7d9a7d..1b0ea6851c 100644 --- a/src/Appwrite/Event/Database.php +++ b/src/Appwrite/Event/Database.php @@ -108,6 +108,10 @@ class Database extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + try { $dsn = new DSN($this->getProject()->getAttribute('database')); } catch (\InvalidArgumentException) { diff --git a/src/Appwrite/Event/Delete.php b/src/Appwrite/Event/Delete.php index 064fbcefa9..1a4c9318e3 100644 --- a/src/Appwrite/Event/Delete.php +++ b/src/Appwrite/Event/Delete.php @@ -140,6 +140,10 @@ class Delete extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Event.php b/src/Appwrite/Event/Event.php index 3f166ad7a4..e3a2e394cf 100644 --- a/src/Appwrite/Event/Event.php +++ b/src/Appwrite/Event/Event.php @@ -65,6 +65,24 @@ class Event { } + /** + * Set paused state for this event. + */ + public function setPaused(bool $paused): self + { + $this->paused = $paused; + + return $this; + } + + /** + * Get paused state for this event. + */ + public function getPaused(): bool + { + return $this->paused; + } + /** * Set queue used for this event. * @@ -302,6 +320,10 @@ class Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Func.php b/src/Appwrite/Event/Func.php index 11a445d8ed..0ad639a9f5 100644 --- a/src/Appwrite/Event/Func.php +++ b/src/Appwrite/Event/Func.php @@ -213,6 +213,10 @@ class Func extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); $events = $this->getEvent() ? Event::generateEvents($this->getEvent(), $this->getParams()) : null; diff --git a/src/Appwrite/Event/Mail.php b/src/Appwrite/Event/Mail.php index 9bdbf6044d..a0fca75688 100644 --- a/src/Appwrite/Event/Mail.php +++ b/src/Appwrite/Event/Mail.php @@ -404,6 +404,10 @@ class Mail extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Messaging.php b/src/Appwrite/Event/Messaging.php index f97ff02d21..ab9b1bee6b 100644 --- a/src/Appwrite/Event/Messaging.php +++ b/src/Appwrite/Event/Messaging.php @@ -182,6 +182,10 @@ class Messaging extends Event */ public function trigger(): string | bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Event/Migration.php b/src/Appwrite/Event/Migration.php index e57ac3c87c..789b8e2160 100644 --- a/src/Appwrite/Event/Migration.php +++ b/src/Appwrite/Event/Migration.php @@ -75,6 +75,9 @@ class Migration extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } $client = new Client($this->queue, $this->connection); diff --git a/src/Appwrite/Event/Realtime.php b/src/Appwrite/Event/Realtime.php index e158076f9b..f4f00b59d4 100644 --- a/src/Appwrite/Event/Realtime.php +++ b/src/Appwrite/Event/Realtime.php @@ -32,7 +32,7 @@ class Realtime extends Event */ public function trigger(): string|bool { - if (empty($this->event)) { + if ($this->paused || empty($this->event)) { return false; } diff --git a/src/Appwrite/Event/Usage.php b/src/Appwrite/Event/Usage.php index 4426f4ab1b..161c251c8e 100644 --- a/src/Appwrite/Event/Usage.php +++ b/src/Appwrite/Event/Usage.php @@ -57,6 +57,10 @@ class Usage extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ 'project' => $this->getProject(), diff --git a/src/Appwrite/Event/UsageDump.php b/src/Appwrite/Event/UsageDump.php index 8f87908849..2998e4e104 100644 --- a/src/Appwrite/Event/UsageDump.php +++ b/src/Appwrite/Event/UsageDump.php @@ -38,6 +38,10 @@ class UsageDump extends Event */ public function trigger(): string|bool { + if ($this->paused) { + return false; + } + $client = new Client($this->queue, $this->connection); return $client->enqueue([ diff --git a/src/Appwrite/Platform/Workers/Certificates.php b/src/Appwrite/Platform/Workers/Certificates.php index 2247a70ef4..e55baa4e1e 100644 --- a/src/Appwrite/Platform/Workers/Certificates.php +++ b/src/Appwrite/Platform/Workers/Certificates.php @@ -520,9 +520,7 @@ class Certificates extends Action private function updateDomainDocuments(string $certificateId, string $domain, bool $success, Database $dbForConsole, Event $queueForEvents, Func $queueForFunctions): void { - $rule = $dbForConsole->findOne('rules', [ - Query::equal('domain', [$domain]), - ]); + $rule = $dbForConsole->getDocument('rules', md5($domain)); if (!$rule->isEmpty()) { $rule->setAttribute('certificateId', $certificateId); diff --git a/src/Appwrite/Platform/Workers/Migrations.php b/src/Appwrite/Platform/Workers/Migrations.php index d430d0eb67..4b1926ed26 100644 --- a/src/Appwrite/Platform/Workers/Migrations.php +++ b/src/Appwrite/Platform/Workers/Migrations.php @@ -268,8 +268,6 @@ class Migrations extends Action $transfer = $source = $destination = null; try { - $migration = $this->dbForProject->getDocument('migrations', $migration->getId()); - if ( $migration->getAttribute('source') === SourceAppwrite::getName() && empty($migration->getAttribute('credentials', [])) diff --git a/tests/e2e/Client.php b/tests/e2e/Client.php index 0774f1c6fd..dc80808b14 100644 --- a/tests/e2e/Client.php +++ b/tests/e2e/Client.php @@ -179,9 +179,14 @@ class Client default => http_build_query($params), }; - foreach ($headers as $i => $header) { - $headers[] = $i . ':' . $header; - unset($headers[$i]); + $formattedHeaders = []; + foreach ($headers as $key => $value) { + if (strtolower($key) === 'accept-encoding') { + curl_setopt($ch, CURLOPT_ENCODING, $value); + continue; + } else { + $formattedHeaders[] = $key . ': ' . $value; + } } curl_setopt($ch, CURLOPT_PATH_AS_IS, 1); @@ -189,7 +194,7 @@ class Client curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/70.0.3538.77 Safari/537.36'); - curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); + curl_setopt($ch, CURLOPT_HTTPHEADER, $formattedHeaders); curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 0); curl_setopt($ch, CURLOPT_TIMEOUT, 15); curl_setopt($ch, CURLOPT_HEADERFUNCTION, function ($curl, $header) use (&$responseHeaders, &$cookies) { @@ -220,7 +225,6 @@ class Client curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); } - $responseBody = curl_exec($ch); $responseType = $responseHeaders['content-type'] ?? ''; $responseStatus = curl_getinfo($ch, CURLINFO_HTTP_CODE); diff --git a/tests/e2e/General/CompressionTest.php b/tests/e2e/General/CompressionTest.php new file mode 100644 index 0000000000..9affacfe0a --- /dev/null +++ b/tests/e2e/General/CompressionTest.php @@ -0,0 +1,137 @@ +client->call(Client::METHOD_GET, '/ping', [ + 'accept-encoding' => 'gzip', + 'x-appwrite-project' => $this->getProject()['$id'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('Pong!', $response['body']); + $this->assertLessThan(1024, strlen($response['body'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + + // without header + $response = $this->client->call(Client::METHOD_GET, '/ping', [ + 'x-appwrite-project' => $this->getProject()['$id'], + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertEquals('Pong!', $response['body']); + $this->assertLessThan(1024, strlen($response['body'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } + + public function testLargeResponse() + { + // create an anonymous user + $response = $this->client->call(Client::METHOD_POST, '/users', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'userId' => ID::unique(), + 'email' => 'test@localhost.test', + 'password' => 'password', + 'name' => 'User Name', + ]); + $this->assertEquals(201, $response['headers']['status-code']); + $userId = $response['body']['$id']; + + // set prefs with 2000 bytes of data + $prefs = ["longValue" => str_repeat('a', 2000)]; + + $response = $this->client->call(Client::METHOD_PATCH, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'content-type' => 'application/json', + ], $this->getHeaders()), [ + 'prefs' => $prefs, + ]); + + $this->assertEquals(200, $response['headers']['status-code']); + + // get prefs with compression + $response = $this->client->call(Client::METHOD_GET, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + 'accept-encoding' => 'gzip', + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertArrayHasKey('content-encoding', $response['headers'], 'Content encoding should be gzip, headers received: ' . json_encode($response['headers'], JSON_PRETTY_PRINT)); + $this->assertLessThan(2000, intval($response['headers']['content-length'])); + + // get prefs without compression + $response = $this->client->call(Client::METHOD_GET, '/users/' . $userId . '/prefs', array_merge([ + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertGreaterThanOrEqual(2000, intval($response['headers']['content-length'])); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } + + public function testImageResponse() + { + // create bucket + $bucket = $this->client->call(Client::METHOD_POST, '/storage/buckets', array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'bucketId' => ID::unique(), + 'name' => 'Test Bucket', + 'fileSecurity' => true, + ]); + $bucketId = $bucket['body']['$id']; + $this->assertEquals(201, $bucket['headers']['status-code']); + + // upload image + $file = $this->client->call(Client::METHOD_POST, '/storage/buckets/' . $bucketId . '/files', array_merge([ + 'content-type' => 'multipart/form-data', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders()), [ + 'fileId' => ID::unique(), + 'file' => new CURLFile(realpath(__DIR__ . '/../../resources/logo.png'), 'image/png', 'logo.png'), + 'permissions' => [ + Permission::read(Role::any()), + Permission::update(Role::any()), + Permission::delete(Role::any()), + ], + ]); + $fileId = $file['body']['$id']; + + // get image with header + $response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([ + 'content-type' => 'application/json', + 'accept-encoding' => 'gzip', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + // get image without + $response = $this->client->call(Client::METHOD_GET, '/storage/buckets/' . $bucketId . '/files/' . $fileId, array_merge([ + 'content-type' => 'application/json', + 'x-appwrite-project' => $this->getProject()['$id'], + ], $this->getHeaders())); + + $this->assertEquals(200, $response['headers']['status-code']); + $this->assertArrayNotHasKey('content-encoding', $response['headers']); + } +} diff --git a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php index b1315103b1..4f4b0c960d 100644 --- a/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php +++ b/tests/e2e/Services/FunctionsSchedule/FunctionsScheduleTest.php @@ -1,12 +1,13 @@