protected function Api::vQuery in Fastly 8.3
Performs http queries to Fastly API server (VCL related).
Parameters
string $uri: The uri to use for the request, appended to the host.
array $data: (optional) Data to send with the request.
string $method: (optional) The method to use for the request, defaults to GET.
array $headers: (optional) An array of headers to send with the request.
Return value
\Psr\Http\Message\ResponseInterface Response.
Throws
\GuzzleHttp\Exception\RequestException RequestException.
1 call to Api::vQuery()
- Api::vclQuery in src/
Api.php - Wraps query method from this class.
File
- src/
Api.php, line 518
Class
- Api
- Fastly API for Drupal.
Namespace
Drupal\fastlyCode
protected function vQuery($uri, array $data = [], $method = 'GET', array $headers = []) {
try {
if (empty($data['headers'])) {
$data['headers'] = $headers;
$data['headers']['Accept'] = 'application/json';
$data['headers']['Fastly-Key'] = $this->apiKey;
// If the module is configured to use soft purging, we need to add
// the appropriate header.
if ($this->purgeMethod == PurgeOptionsForm::FASTLY_SOFT_PURGE) {
$data['headers']['Fastly-Soft-Purge'] = 1;
}
$data['headers']['http_errors'] = TRUE;
}
$uri = ltrim($uri, '/');
$uri = $this->host . $uri;
$uri = rtrim($uri, '/');
switch (strtoupper($method)) {
case 'GET':
case 'POST':
case 'PURGE':
case 'PATCH':
case 'PUT':
case 'DELETE':
$data["http_errors"] = FALSE;
return $this->httpClient
->request($method, $uri, $data);
default:
throw new \Exception('Method :method is not valid for Fastly service.', [
':method' => $method,
]);
}
} catch (\Exception $e) {
$this->logger
->critical($e
->getMessage());
}
return new Response();
}