mirror of
https://gitee.com/fasiondog/hikyuu.git
synced 2024-11-30 19:08:48 +08:00
hku server continue
This commit is contained in:
parent
fd30c9bfd3
commit
881f222e2d
@ -31,7 +31,9 @@ void HttpHandle::operator()() {
|
||||
|
||||
before_run();
|
||||
run();
|
||||
after_run();
|
||||
|
||||
// nng_http_res_set_status(m_nng_res, NNG_HTTP_STATUS_OK);
|
||||
nng_aio_set_output(m_http_aio, 0, m_nng_res);
|
||||
nng_aio_finish(m_http_aio, 0);
|
||||
|
||||
@ -107,7 +109,7 @@ std::string HttpHandle::getReqData() {
|
||||
|
||||
bool HttpHandle::haveQueryParams() {
|
||||
const char* url = nng_http_req_get_uri(m_nng_req);
|
||||
return !url ? false : strchr(url, '?');
|
||||
return !url ? false : strchr(url, '?') != nullptr;
|
||||
}
|
||||
|
||||
bool HttpHandle::getQueryParams(QueryParams& query_params) {
|
||||
|
@ -49,6 +49,9 @@ public:
|
||||
/** 响应处理 */
|
||||
virtual void run() = 0;
|
||||
|
||||
/** 后处理 */
|
||||
virtual void after_run() {}
|
||||
|
||||
void addFilter(std::function<void(HttpHandle *)> filter) {
|
||||
m_filters.push_back(filter);
|
||||
}
|
||||
|
@ -30,6 +30,11 @@ public:
|
||||
virtual void before_run() override {
|
||||
setResHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
}
|
||||
|
||||
virtual void after_run() override {
|
||||
// 强制关闭连接,即仅有短连接
|
||||
nng_http_res_set_status(m_nng_res, NNG_HTTP_STATUS_OK);
|
||||
}
|
||||
};
|
||||
|
||||
#define REST_HANDLE_IMP(cls) \
|
||||
|
@ -24,6 +24,7 @@ class LogLevelHandle : public RestHandle {
|
||||
if (!req.contains("logger")) {
|
||||
set_logger_level(level);
|
||||
setResData(R"({"result": true})");
|
||||
return;
|
||||
}
|
||||
|
||||
HTTP_VALID_CHECK(req["logger"].is_string(), HttpValidErrorCode::WRONG_PARAMETER_TYPE,
|
||||
@ -31,10 +32,10 @@ class LogLevelHandle : public RestHandle {
|
||||
std::string logger = req["logger"].get<std::string>();
|
||||
if (have_logger(logger)) {
|
||||
set_logger_level(logger, level);
|
||||
setResData(R"({"result": true})");
|
||||
} else {
|
||||
setResData(fmt::format(
|
||||
R"({{"result":false, "errcode": 2000, "errmsg":"not exist logger {}"}})", logger));
|
||||
return;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -17,6 +17,7 @@ class LoginHandle : public HttpHandle {
|
||||
virtual void run() override {
|
||||
json req = getReqJson();
|
||||
HTTP_VALID_CHECK(req.contains("user"), 2000, "Invalid login request! missing user");
|
||||
setResHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
setResData(
|
||||
R"({"hku_token":"7c98806c0711cf996d602890e0ab9119d9a86afe04296ba69a16f0d9d76be755"})");
|
||||
}
|
||||
|
@ -15,6 +15,7 @@ class LogoutHandle : public HttpHandle {
|
||||
HTTP_HANDLE_IMP(LogoutHandle)
|
||||
|
||||
virtual void run() override {
|
||||
setResHeader("Content-Type", "application/json; charset=UTF-8");
|
||||
setResData(R"({"result": true})");
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user