Files
zaloopipe/pipeline-runner/src/messageutils.cpp
T
2026-07-16 08:40:05 +03:00

32 lines
764 B
C++

#include "messageutils.h"
#include <pihttpserver.h>
namespace MessageUtils {
PIHTTP::MessageMutable jsonReply(PIHTTP::Code code, const PIJSON & json) {
PIHTTP::MessageMutable msg;
msg.setCode(code);
msg.setBody(json.toJSON(PIJSON::Compact).toUTF8());
msg.addHeader("Content-Type", "application/json; charset=utf-8");
return msg;
}
PIHTTP::MessageMutable errorReply(PIHTTP::Code code, const PIString & message) {
PIJSON j = PIJSON::newObject();
j["error"] = message;
return jsonReply(code, j);
}
PIHTTP::MessageMutable successReply(const PIJSON & json) {
return jsonReply(PIHTTP::Code::Ok, json);
}
PIHTTP::MessageMutable noContent() {
PIHTTP::MessageMutable msg;
msg.setCode(PIHTTP::Code::NoContent);
return msg;
}
} // namespace MessageUtils