Don't expect Contet-Type header to exactly match application/json

InfluxDB seems to always include some other metadata in the `Content-Type`
header separated by semicolons like `application/json; charset=utf-8`,
and comparing the whole string with `application/json` will always fail,
resulting in almost always useless warnings without any helpful information
for the user what actually went wrong.
This commit is contained in:
Yonas Habteab 2025-09-16 12:06:23 +02:00
parent 41a2148be4
commit b68a44d047

View File

@ -493,31 +493,8 @@ void InfluxdbCommonWriter::FlushWQ()
auto& response (parser.get());
if (response.result() != http::status::no_content) {
Log(LogWarning, GetReflectionType()->GetName())
<< "Unexpected response code: " << response.result();
auto& contentType (response[http::field::content_type]);
if (contentType != "application/json") {
Log(LogWarning, GetReflectionType()->GetName())
<< "Unexpected Content-Type: " << contentType;
return;
}
Dictionary::Ptr jsonResponse;
auto& body (response.body());
try {
jsonResponse = JsonDecode(body);
} catch (...) {
Log(LogWarning, GetReflectionType()->GetName())
<< "Unable to parse JSON response:\n" << body;
return;
}
String error = jsonResponse->Get("error");
Log(LogCritical, GetReflectionType()->GetName())
<< "InfluxDB error message:\n" << error;
<< "Unexpected response code: " << response.result() << ", InfluxDB error message:\n" << response.body();
}
}