Refactor Guzzle HTTP requests for flexibility and proxy support

Restructured Guzzle HTTP requests to allow for additional options like proxy support, enhancing flexibility in handling different types of requests.
This commit is contained in:
Jeroen De Meerleer 2024-06-03 13:33:43 +02:00
parent bcb0d0b23d
commit 1dfddd64ba
No known key found for this signature in database
GPG Key ID: 3B23D1B3498D7641

View File

@ -11,15 +11,28 @@ if($_SERVER["REQUEST_URI"] == '/metrics') {
$output = implode("\n", $output);
} elseif(isset($c['httpurl'])) {
$client = new GuzzleHttp\Client();
$res = $client->get($c['httpurl']);
$options = [];
if (isset($c['proxy'])) {
$options['proxy'] = $c['proxy'];
}
$res = $client->request('GET', $c['httpurl'], $options);
$output = $res->getBody()->getContents();
} elseif(isset($c['httpresponsetime'])) {
$client = new GuzzleHttp\Client();
$output = NULL;
$res = $client->request('GET', $c['httpresponsetime'], [
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
$output = $stats->getTransferTime();
}]);
$options = [
'on_stats' => function (GuzzleHttp\TransferStats $stats) use (&$output) {
$output = $stats->getTransferTime();
}
];
if (isset($c['proxy'])) {
$options['proxy'] = $c['proxy'];
}
$res = $client->request('GET', $c['httpresponsetime'], $options);
}
if(isset($c['jsonelem'])) {
$c['value'] = getArrayValue($c['jsonelem'], json_decode($output, true));