Gets the message for the specified HTTP code
public static getCodeMessage ( integer $code ) : string | ||
$code | integer | |
return | string | Returns the message for the specified HTTP code |
/** * Asserts describe response has all properties and deprecated paths response are identical current response * * @param string $basePath * @param array $listPaths * @param bool $environment optional if variable is true replace envId for test environment */ public function assertApiListResponse($basePath, $listPaths, $environment = false) { $this->assertNotEmpty($listPaths); foreach ($listPaths as $path => $property) { $pathInfo = $basePath . $path; if ($environment) { $pathInfo = str_replace('{envId}', static::$testEnvId, $pathInfo); } $resp = $this->request($pathInfo, Request::METHOD_GET); $envelope = $resp->getBody(); $this->assertDescribeResponseNotEmpty($resp); $pathInfoDeprecated = preg_replace("#/(v\\d.*?)/(user|admin|account)/#", '/$2/$1/', $pathInfo); $resDepPath = $this->request($pathInfoDeprecated, Request::METHOD_GET); $this->assertDescribeResponseNotEmpty($resDepPath); $envelopeDep = $resDepPath->getBody(); $this->assertObjectHasAttribute('warnings', $envelopeDep); $this->assertNotEmpty($envelopeDep->warnings); $code = []; $message = []; /* @var $warning ApiMessage */ foreach ($envelopeDep->warnings as $warning) { $code[] = $warning->code; $message[] = $warning->message; } $this->assertContains(Response::getCodeMessage(301), $code); $this->assertContains(sprintf('Location %s', $pathInfo), $message); $this->assertEquals($envelope->data, $envelopeDep->data); } }
/** * {@inheritdoc} * @see \Scalr\Api\Rest\Application::__construct() */ public function __construct(array $settings = []) { parent::__construct($settings); $cont = $this->getContainer(); $cont->api->setShared('meta', function ($cont) { return new Meta(); }); $cont->api->setShared('warnings', function () { return new Warnings(); }); $this->pathPreprocessor = function ($method, $pathInfo) { if (preg_match("#^/api/(user|admin|account)/#", $pathInfo)) { $pathInfo = preg_replace("#/(user|admin|account)/(v\\d.*?)/#", '/$2/$1/', $pathInfo); $this->warnings->appendWarnings(Response::getCodeMessage(301), sprintf('Location %s', $pathInfo)); } return [$method, $pathInfo]; }; $this->limiter = new Limiter(\Scalr::getContainer()->config->{'scalr.system.api.limits'}); }
/** * Runs application */ public function run() { $this->response->setHeader('X-Scalr-Inittime', microtime(true) - $this->startTime); $this->call(); $this->response->setHeader('X-Scalr-Actiontime', microtime(true) - $this->startTime); //Fetch status, header, and body list($status, $headers, $body) = $this->response->finalize(); if (headers_sent() === false) { if (strpos(PHP_SAPI, 'cgi') === 0) { header(sprintf('Status: %s', Response::getCodeMessage($status))); } else { header(sprintf('HTTP/%s %s', '1.1', Response::getCodeMessage($status))); } @header_remove('X-Powered-By'); if (isset($this->settings[static::SETTING_API_VERSION])) { $headers['X-Powered-By'] = sprintf("Scalr API/%s", $this->settings[static::SETTING_API_VERSION]); } //Send headers foreach ($headers as $name => $value) { //Normalizes the header name $name = implode('-', array_map(function ($v) { return ucfirst(strtolower($v)); }, preg_split('/[_-]/', $name))); $a = explode("\n", $value); if ($a) { foreach ($a as $v) { header("{$name}: {$v}", false); } } } } if ($this->request->getMethod() !== Request::METHOD_HEAD) { echo $body; } }