1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- /*
- * @Author: error: git config user.name && git config user.email & please set dead value or install git
- * @Date: 2022-07-10 16:34:00
- * @LastEditors: error: git config user.name && git config user.email & please set dead value or install git
- * @LastEditTime: 2022-07-10 22:43:12
- * @FilePath: /gsd/plugins/httpHelper.cpp
- * @Description: 这是默认设置,请设置`customMade`, 打开koroFileHeader查看配置 进行设置: https://github.com/OBKoro1/koro1FileHeader/wiki/%E9%85%8D%E7%BD%AE
- */
- /**
- *
- * httpHelper.cc
- *
- */
- #include "httpHelper.hpp"
- #include "HttpNull.hpp"
- #include "HttpToken.hpp"
- #include "HttpResultMsg.hpp"
- using namespace std;
- using namespace drogon;
- void httpHelper::initAndStart(const Json::Value &config)
- {
- /// Initialize and start the plugin
- }
- void httpHelper::shutdown()
- {
- /// Shutdown the plugin
- }
- /**
- * @description: 创建错误恢复
- * @return {*}
- */
- HttpResponsePtr httpHelper::makeWrongReply(std::string data){
- HttpResultMsg<HttpNull, HttpNull> msg;
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- msg.code = "502";
- msg.status = "Failure";
- msg.msg = data;
- msg.attr1 = "服务不可用";
- std::string json;
- msg.objectToJson(json);
- resp->setStatusCode(k502BadGateway);
- resp->setBody(json);
- return resp;
- }
- /**
- * @description: 回复请求
- * @param {pair<ReqResult, HttpResponsePtr>} result
- * @param {function<void (HttpResponsePtr &)>} &
- * @return {*}
- */
- HttpResponsePtr httpHelper::replyRequest(std::pair<ReqResult, HttpResponsePtr> result, const HttpMethod method){
- HttpResultMsg<HttpNull, HttpNull> msg;
- HttpResponsePtr resp;
- resp = HttpResponse::newHttpResponse();
- std::string json;
- if(result.first != ReqResult::Ok){
- ErrorL << "error while sending request to server! result " << result.first << std::endl;
- msg.code = "502";
- msg.status = "Failure";
- msg.attr1 = "服务不可用";
- msg.objectToJson(json);
- resp->setBody(json);
- return resp;
- }
- resp->setStatusCode(result.second->getStatusCode());
- msg.code = std::to_string(result.second->getStatusCode());
- msg.status = "Failure";
- msg.attr1 = result.second->getBody().data();
- switch (method)
- {
- case Get:
- if(result.second->getStatusCode() == k200OK) msg.status = "Success";
- break;
- case Post:
- if(result.second->getStatusCode() == k201Created) msg.status = "Success";
- break;
- case Delete:
- if(result.second->getStatusCode() == k200OK) msg.status = "Success";
- break;
- case Put:
- if(result.second->getStatusCode() == k200OK) msg.status = "Success";
- break;
- default:
- break;
- }
- msg.attr1 = result.second->getBody().data();
- msg.objectToJson(json);
- resp->setBody(json);
- return resp;
- }
|