From 88708240c766b34ade49a0f0828d27d86c8f2179 Mon Sep 17 00:00:00 2001 From: Michael <33117529+mtelgkamp@users.noreply.github.com> Date: Mon, 31 May 2021 04:02:20 +0200 Subject: [PATCH] Add error message for missing/invalid header (#1017) * add error message for missing/invalid header * Code cleanup - simplify the check - do not invert the result of `preg_match()` - do not set the `$result` in loop, it is already set after the loop - fix the order of code, first set `$this->error` then `$result` --- src/psm/Util/Server/Updater/StatusUpdater.php | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/psm/Util/Server/Updater/StatusUpdater.php b/src/psm/Util/Server/Updater/StatusUpdater.php index 5cc42f1c..e299ae98 100644 --- a/src/psm/Util/Server/Updater/StatusUpdater.php +++ b/src/psm/Util/Server/Updater/StatusUpdater.php @@ -331,19 +331,19 @@ class StatusUpdater list ($key, $value) = explode(': ', $line); // Header found (case-insensitive) if (strcasecmp($key, $this->server['header_name']) == 0) { - // The value doesn't match what we needed - if (!preg_match("/{$this->server['header_value']}/i", $value)) { - $result = false; - } else { + // The value matches what we need, everything is fine + if (preg_match("/{$this->server['header_value']}/i", $value)) { $header_flag = true; - break; // No need to go further + break; // The correct header is found, we leave the loop } } } } if (!$header_flag) { - // Header was not present + // Header was not present, set error message and $result variable + $this->error = 'HEADER ERROR : Header "' . $this->server['header_name'] . + '" not found or does not match "/' . $this->server['header_value'] . '/i".'; $result = false; } } @@ -447,7 +447,7 @@ class StatusUpdater socket_send($socket, $package, strLen($package), 0); // socket_read returns a string or false $status = socket_read($socket, 255) !== false ? true : false; - + if ($status) { $this->header = "Success."; } else {