Request handling.

This commit is contained in:
Relintai 2021-07-06 18:59:30 +02:00
parent 47f9e21a91
commit f03b983de2
4 changed files with 14 additions and 24 deletions

View File

@ -23,6 +23,10 @@ void DRequest::compile_body() {
"</html>";
response->setBody(compiled_body);
//request->response->setBody("<p>Hello, world!</p>");
//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);
}

View File

@ -17,7 +17,7 @@ class DRequest {
public:
HttpResponsePtr response;
HttpRequestImplPtr request;
std::function<void(const HttpResponsePtr &)> *callback;
std::function<void(const HttpResponsePtr &)> callback;
DWebApplication *application;

View File

@ -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("<p>Hello, world!</p>");
//resp->setExpiredTime(0);
//callback(resp);
request->response->setBody("<p>Hello, world!</p>");
request->response->setExpiredTime(0);
request->callback->operator()(request->response);
//request->response->setBody("<p>Hello, world!</p>");
//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<drogon::HttpRequestImpl>(req);
request->callback = &callback;//std::move(callback);
request->callback = callback;//std::move(callback);
request->setup_url_stack();

View File

@ -1,5 +1,5 @@
#ifndef DWEB_APPLICATION_H
#define WEB_APPLICATION_H
#define DWEB_APPLICATION_H
#include "core/object.h"
#include <functional>