From f03b983de2d4266cc2cba58b91deea08adfda1e8 Mon Sep 17 00:00:00 2001 From: Relintai Date: Tue, 6 Jul 2021 18:59:30 +0200 Subject: [PATCH] Request handling. --- modules/drogon/request.cpp | 22 ++++++---------------- modules/drogon/request.h | 2 +- modules/drogon/web_application.cpp | 12 ++++++------ modules/drogon/web_application.h | 2 +- 4 files changed, 14 insertions(+), 24 deletions(-) diff --git a/modules/drogon/request.cpp b/modules/drogon/request.cpp index a1f36ed..5ddb3f9 100644 --- a/modules/drogon/request.cpp +++ b/modules/drogon/request.cpp @@ -23,6 +23,10 @@ void DRequest::compile_body() { ""; response->setBody(compiled_body); + + //request->response->setBody("

Hello, world!

"); + //request->response->setExpiredTime(0); + //request->callback(request->response); } void DRequest::compile_and_send_body() { @@ -47,23 +51,9 @@ void DRequest::send() { // return; //} -/* - if (http_parser->isKeepAlive()) { - response->addHeadValue("Connection", "Keep-Alive"); + //response->setExpiredTime(0); + callback(response); - std::string result = response->getResult(); - - session->send(result.c_str(), result.size()); - } else { - response->addHeadValue("Connection", "Close"); - - std::string result = response->getResult(); - - HttpSession::Ptr lsession = session; - - session->send(result.c_str(), result.size(), [lsession]() { lsession->postShutdown(); }); - } -*/ DRequestPool::return_request(this); } diff --git a/modules/drogon/request.h b/modules/drogon/request.h index 40139f7..f1e919a 100644 --- a/modules/drogon/request.h +++ b/modules/drogon/request.h @@ -17,7 +17,7 @@ class DRequest { public: HttpResponsePtr response; HttpRequestImplPtr request; - std::function *callback; + std::function callback; DWebApplication *application; diff --git a/modules/drogon/web_application.cpp b/modules/drogon/web_application.cpp index 8995ad7..970b073 100644 --- a/modules/drogon/web_application.cpp +++ b/modules/drogon/web_application.cpp @@ -88,19 +88,19 @@ void DWebApplication::default_404_error_handler(int error_code, DRequest *reques } void DWebApplication::handle_request(DRequest *request) { - //request->middleware_stack = &middlewares; + request->middleware_stack = &middlewares; //note that middlewares handle the routing -> DWebApplication::default_routing_middleware by default - //request->next_stage(); + request->next_stage(); //auto resp = HttpResponse::newHttpResponse(); //resp->setBody("

Hello, world!

"); //resp->setExpiredTime(0); //callback(resp); - request->response->setBody("

Hello, world!

"); - request->response->setExpiredTime(0); - request->callback->operator()(request->response); + //request->response->setBody("

Hello, world!

"); + //request->response->setExpiredTime(0); + //request->callback(request->response); DRequestPool::return_request(request); } @@ -658,7 +658,7 @@ void DWebApplication::on_async_request(const HttpRequestImplPtr &req, std::funct request->application = this; request->response = HttpResponse::newHttpResponse(); request->request = std::shared_ptr(req); - request->callback = &callback;//std::move(callback); + request->callback = callback;//std::move(callback); request->setup_url_stack(); diff --git a/modules/drogon/web_application.h b/modules/drogon/web_application.h index e57681d..69716bc 100644 --- a/modules/drogon/web_application.h +++ b/modules/drogon/web_application.h @@ -1,5 +1,5 @@ #ifndef DWEB_APPLICATION_H -#define WEB_APPLICATION_H +#define DWEB_APPLICATION_H #include "core/object.h" #include