# HG changeset patch # User František Kučera # Date 1648845602 -7200 # Node ID 33f8162a497122107d8dad1c7af31162c7bdf701 # Parent 1bbfcb95db8200f285de64c2784d6c79a2f94036 return at least ASCII text when unable to decode diff -r 1bbfcb95db82 -r 33f8162a4971 src/HTTPHandler.h --- 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();