Merge pull request #8532 from Icinga/bugfix/do-not-override-error-codes-that-are-not-200

HTTP: Do not override status codes that are not 200
This commit is contained in:
Julian Brost 2021-01-14 09:34:04 +01:00 committed by GitHub
commit db30704d14
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 22 additions and 3 deletions

View File

@ -100,12 +100,31 @@ bool ActionsHandler::HandleRequest(
}
int statusCode = 500;
std::set<int> okStatusCodes, nonOkStatusCodes;
for (const Dictionary::Ptr& res : results) {
if (res->Contains("code") && res->Get("code") >= 200 && res->Get("code") <= 299) {
statusCode = 200;
break;
if (!res->Contains("code")) {
continue;
}
auto code = res->Get("code");
if (code >= 200 && code <= 299) {
okStatusCodes.insert(code);
} else {
nonOkStatusCodes.insert(code);
}
}
size_t okSize = okStatusCodes.size();
size_t nonOkSize = nonOkStatusCodes.size();
if (okSize == 1u && nonOkSize == 0u) {
statusCode = *okStatusCodes.begin();
} else if (nonOkSize == 1u) {
statusCode = *nonOkStatusCodes.begin();
} else if (okSize >= 2u && nonOkSize == 0u) {
statusCode = 200;
}
response.result(statusCode);