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`
This commit is contained in:
Michael 2021-05-31 04:02:20 +02:00 committed by GitHub
parent 9c8ed81203
commit 88708240c7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 7 deletions

View File

@ -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 {