2020-11-25 00:20:41 +01:00
|
|
|
#ifndef REQUEST_H
|
|
|
|
#define REQUEST_H
|
|
|
|
|
|
|
|
#include <mutex>
|
2020-11-26 11:26:02 +01:00
|
|
|
#include <vector>
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
#include <brynet/net/http/HttpFormat.hpp>
|
2020-11-26 11:26:02 +01:00
|
|
|
#include <brynet/net/http/HttpService.hpp>
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-12-01 12:56:04 +01:00
|
|
|
#include "handler_instance.h"
|
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
using namespace brynet;
|
|
|
|
using namespace brynet::net;
|
|
|
|
using namespace brynet::net::http;
|
|
|
|
|
|
|
|
class Request {
|
|
|
|
public:
|
|
|
|
const HTTPParser *http_parser;
|
2020-11-26 11:26:02 +01:00
|
|
|
const HttpSession::Ptr *session;
|
2020-11-25 00:20:41 +01:00
|
|
|
HttpResponse *response;
|
|
|
|
|
2020-11-26 12:02:58 +01:00
|
|
|
uint32_t current_middleware_index;
|
2020-12-01 12:56:04 +01:00
|
|
|
HandlerInstance handler_instance;
|
|
|
|
std::vector<HandlerInstance> *middleware_stack;
|
2020-11-26 12:02:58 +01:00
|
|
|
|
2020-12-11 16:54:41 +01:00
|
|
|
std::string head;
|
|
|
|
std::string body;
|
2020-12-26 00:17:36 +01:00
|
|
|
std::string footer;
|
2020-12-11 16:54:41 +01:00
|
|
|
std::string compiled_body;
|
|
|
|
|
|
|
|
void compile_body();
|
|
|
|
void compile_and_send_body();
|
2020-11-26 12:02:58 +01:00
|
|
|
void next_stage();
|
2020-11-26 11:26:02 +01:00
|
|
|
void send();
|
|
|
|
void reset();
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-11-26 11:26:02 +01:00
|
|
|
Request();
|
|
|
|
~Request();
|
2020-11-25 00:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
class RequestPool {
|
|
|
|
public:
|
2020-11-26 11:26:02 +01:00
|
|
|
static Request *get_request();
|
|
|
|
static void return_request(Request *request);
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-11-26 11:26:02 +01:00
|
|
|
RequestPool();
|
|
|
|
~RequestPool();
|
2020-11-25 00:20:41 +01:00
|
|
|
|
|
|
|
protected:
|
2020-11-26 11:26:02 +01:00
|
|
|
static std::mutex _mutex;
|
|
|
|
static std::vector<Request *> _requests;
|
2020-11-25 00:20:41 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif
|