add: Response 添加一个json方法,便捷的回复json格式数据;request添加一个context成员,便于在处理链的各个环节共享数据

This commit is contained in:
2020-12-16 19:50:24 +08:00
parent 0b69f61217
commit 1beaf2cbee
4 changed files with 14 additions and 3 deletions
+4
View File
@@ -43,6 +43,10 @@ namespace MIN {
// queryParams
MIN_MAP<std::string, std::string> queryParams;
// 上下文数据
// 可以再 preprocessor -> controller -> postprocessor 这条处理链的任意缓解向上下文中存取信息
nlohmann::json context;
void init() {
type = MIN_WEB_REQUEST;
}
+4
View File
@@ -5,4 +5,8 @@
#include "MINWebResponse.h"
namespace MIN {
void MINWebResponse::json(const nlohmann::json &jsonData) {
this->contentType = MINWebServer::APPLICATION_JSON;
this->body = jsonData.dump();
}
}
+6
View File
@@ -37,6 +37,12 @@ namespace MIN {
void init() {
type = MIN_WEB_RESPONSE;
}
/**
* 返回JSON格式的数据
* @param jsonData
*/
void json(const nlohmann::json &jsonData);
};
}
-3
View File
@@ -45,9 +45,6 @@ int main () {
service.homePage = "index.html";
service.baseUrl = "/MIN/Web/test";
std::cout << getMINHttpMethodEnumFromStr("GET") << std::endl;
std::cout << getMINHttpStatusEnumFromStr("Continue") << std::endl;
service.GET("/getUserInfo", [](std::shared_ptr<MINWebRequest> &request,
std::shared_ptr<MINWebResponse> &response) {
nlohmann::json result = {