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"
|
|
|
|
|
2021-02-08 11:01:15 +01:00
|
|
|
using namespace brynet;
|
|
|
|
using namespace brynet::net;
|
|
|
|
using namespace brynet::net::http;
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2021-04-28 22:50:05 +02:00
|
|
|
class Application;
|
|
|
|
|
2020-11-25 00:20:41 +01:00
|
|
|
class Request {
|
|
|
|
public:
|
2021-02-09 01:25:24 +01:00
|
|
|
HTTPParser::Ptr http_parser;
|
|
|
|
HttpSession::Ptr session;
|
2021-02-08 11:01:15 +01:00
|
|
|
HttpResponse *response;
|
2021-04-28 22:50:05 +02:00
|
|
|
Application *application;
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-12-28 19:15:27 +01:00
|
|
|
uint32_t current_middleware_index;
|
|
|
|
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;
|
|
|
|
|
2021-01-08 02:55:41 +01:00
|
|
|
std::string file_path;
|
|
|
|
long file_size;
|
|
|
|
long current_file_progress;
|
|
|
|
long file_chunk_size;
|
|
|
|
bool file_next;
|
|
|
|
|
2021-02-09 01:25:24 +01:00
|
|
|
bool connection_closed;
|
|
|
|
|
2020-12-11 16:54:41 +01:00
|
|
|
void compile_body();
|
|
|
|
void compile_and_send_body();
|
2020-12-28 19:15:27 +01:00
|
|
|
void next_stage();
|
2020-11-26 11:26:02 +01:00
|
|
|
void send();
|
2021-01-08 02:55:41 +01:00
|
|
|
void send_file(const std::string &p_file_path);
|
2021-04-28 22:50:05 +02:00
|
|
|
void send_error(int error_code);
|
2020-11-26 11:26:02 +01:00
|
|
|
void reset();
|
2020-11-25 00:20:41 +01:00
|
|
|
|
2020-12-28 19:15:27 +01:00
|
|
|
void setup_url_stack();
|
|
|
|
std::string get_path() const;
|
|
|
|
const std::string &get_path_full() const;
|
|
|
|
const std::string &get_path_segment(const uint32_t i) const;
|
|
|
|
const std::string &get_current_path_segment() const;
|
|
|
|
uint32_t get_path_segment_count() const;
|
|
|
|
uint32_t get_current_segment_index() const;
|
|
|
|
uint32_t get_remaining_segment_count() const;
|
|
|
|
void pop_path();
|
|
|
|
void push_path();
|
|
|
|
|
2021-02-09 01:25:24 +01:00
|
|
|
void update();
|
|
|
|
|
2020-11-26 11:26:02 +01:00
|
|
|
Request();
|
|
|
|
~Request();
|
2020-12-28 19:15:27 +01:00
|
|
|
|
|
|
|
protected:
|
2021-01-08 02:55:41 +01:00
|
|
|
void _progress_send_file();
|
2021-02-09 01:25:24 +01:00
|
|
|
void _file_chunk_sent();
|
2021-01-08 02:55:41 +01:00
|
|
|
|
2020-12-28 19:15:27 +01:00
|
|
|
std::vector<std::string> _path_stack;
|
|
|
|
uint32_t _path_stack_pointer;
|
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
|