rewrite all to PIP
This commit is contained in:
@@ -0,0 +1,31 @@
|
||||
#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
|
||||
Reference in New Issue
Block a user