From fd8a67c23c3c5c4c09ad2c6df324c351f2e1974f Mon Sep 17 00:00:00 2001 From: Jeroen De Meerleer Date: Tue, 4 Jun 2024 13:22:16 +0200 Subject: [PATCH] Refactor conditional logic for response handling - Adjusted code to handle different scenarios when processing responses. --- index.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/index.php b/index.php index 483e467..07e185f 100644 --- a/index.php +++ b/index.php @@ -47,9 +47,17 @@ if(php_sapi_name() == 'cli' || $_SERVER["REQUEST_URI"] == '/metrics') { } if (isset($submetric['http']['data']) && $submetric['http']['data'] == 'responsebody') { - $output = $res->getBody()->getContents(); + if ($hasresponse) { + $output = $res->getBody()->getContents(); + } else { + $output = ''; + } } elseif ((isset($submetric['http']['statuscode'])) && (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse')) { - $output = (int)in_array($res->getStatusCode(), $submetric['http']['statuscode']); + if ($hasresponse) { + $output = $output = (int)in_array($res->getStatusCode(), $submetric['http']['statuscode']);; + } else { + $output = 0; + } } elseif (isset($submetric['http']['data']) && $submetric['http']['data'] == 'hasresponse') { $output = (int)$hasresponse; }