--- a/src/HTTPHandler.h Fri Mar 25 00:39:11 2022 +0100
+++ b/src/HTTPHandler.h Fri Apr 01 22:40:02 2022 +0200
@@ -133,10 +133,13 @@
relpipe::common::type::StringX bodyToText(const std::string& body, bool* validEncoding = nullptr) {
try {
if (validEncoding) *validEncoding = true;
+ // TODO: use encoding from the HTTP response headers instead of the constant one?
return convertor.from_bytes(body);
} catch (...) {
if (validEncoding) *validEncoding = false;
- return L"";
+ std::stringstream filtered;
+ for (char ch : body) filtered << (ch >= ' ' && ch < 127 ? ch : '.');
+ return convertor.from_bytes(filtered.str());
}
}
@@ -170,6 +173,7 @@
{L"url", relpipe::writer::TypeId::STRING},
{L"text", relpipe::writer::TypeId::STRING},
{L"data", relpipe::writer::TypeId::STRING},
+ {L"text_valid", relpipe::writer::TypeId::BOOLEAN},
{L"code", relpipe::writer::TypeId::INTEGER},
}, true);
}
@@ -240,10 +244,12 @@
// TODO: move error message into separate attribute?
}
+ bool validText = false;
relationalWriter->writeAttribute(requestId);
relationalWriter->writeAttribute(convertor.from_bytes(request.url));
- relationalWriter->writeAttribute(bodyToText(body));
+ relationalWriter->writeAttribute(bodyToText(body, &validText));
relationalWriter->writeAttribute(bodyToHex(body)); // TODO: return as an octet-string (when supported) instead of hexadecimal
+ relationalWriter->writeAttribute(&validText, typeid (validText));
relationalWriter->writeAttribute(&responseCode, typeid (responseCode));
request = HTTPClient::Request();