1
0
Fork 0
mirror of synced 2024-06-02 19:04:49 +12:00

feat: added check for header on api init

This commit is contained in:
Christy Jacob 2020-12-30 00:37:33 +05:30
parent 2ffb34fab1
commit 51600bc1d9
2 changed files with 24 additions and 1 deletions

View file

@ -16,12 +16,23 @@ use Appwrite\Database\Validator\Authorization;
use Appwrite\Network\Validator\Origin;
use Appwrite\Storage\Device\Local;
use Appwrite\Storage\Storage;
use Appwrite\Utopia\Response\Filter;
use Appwrite\Utopia\Response\Filter\V06;
use Utopia\CLI\Console;
Config::setParam('domainVerification', false);
Config::setParam('cookieDomain', 'localhost');
Config::setParam('cookieSamesite', Response::COOKIE_SAMESITE_NONE);
function mapResponseFormatToClass(string $responseFormat): Filter {
switch($responseFormat) {
case preg_match($responseFormat, "/0\.[0-6]\.\d/"):
return new V06();
default:
return null;
}
}
App::init(function ($utopia, $request, $response, $console, $project, $user, $locale, $events, $audits, $usage, $deletes, $clients) {
/** @var Utopia\Swoole\Request $request */
/** @var Appwrite\Utopia\Response $response */
@ -92,6 +103,18 @@ App::init(function ($utopia, $request, $response, $console, $project, $user, $lo
Storage::setDevice('files', new Local(APP_STORAGE_UPLOADS.'/app-'.$project->getId()));
Storage::setDevice('functions', new Local(APP_STORAGE_FUNCTIONS.'/app-'.$project->getId()));
/*
* Response format
*/
$responseFormatEnvVar = App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '');
$responseFormatHeader = $request->getHeader('x-appwrite-response-format', '');
$responseFormat = empty($responseFormatHeader) ? $responseFormatEnvVar : $responseFormatHeader;
if (empty($responseFormat) || ($filter = mapResponseFormatToClass($responseFormat)) == null) {
throw new Exception('No filter available for response format : '.$responseFormat, 404);
} else {
Response::setFilter($filter);
}
/*
* Security Headers
*

View file

@ -23,7 +23,7 @@ error_reporting(E_ALL);
$http = new Server("0.0.0.0", 80);
$payloadSize = max(4000000 /* 4mb */, App::getEnv('_APP_STORAGE_LIMIT', 10000000 /* 10mb */));
$responseFormat = App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', null);
$responseFormat = App::getEnv('_APP_SYSTEM_RESPONSE_FORMAT', '');
$http
->set([