Added http method support to the request class.

This commit is contained in:
Relintai 2021-08-05 17:11:13 +02:00
parent 6ea8d3e39a
commit 543f1eed30
5 changed files with 31 additions and 0 deletions

15
core/http/http_enums.h Normal file
View File

@ -0,0 +1,15 @@
#ifndef HTTP_ENUMS_H
#define HTTP_ENUMS_H
enum HTTPMethod {
HTTP_METHOD_GET = 0,
HTTP_METHOD_POST,
HTTP_METHOD_HEAD,
HTTP_METHOD_PUT,
HTTP_METHOD_DELETE,
HTTP_METHOD_OPTIONS,
HTTP_METHOD_PATCH,
HTTP_METHOD_INVALID,
};
#endif

View File

@ -14,6 +14,10 @@ void Request::add_cookie(const ::Cookie &cookie) {
void Request::remove_cookie(const std::string &key) {
}
HTTPMethod Request::get_method() const {
return HTTP_METHOD_GET;
}
void Request::compile_body() {
compiled_body.reserve(body.size() + head.size() + 13 + 14 + 15);

View File

@ -9,6 +9,8 @@
#include "handler_instance.h"
#include "http_enums.h"
class WebApplication;
class Cookie;
class HTTPSession;
@ -41,6 +43,8 @@ public:
virtual void add_cookie(const ::Cookie &cookie);
virtual void remove_cookie(const std::string &key);
virtual HTTPMethod get_method() const;
virtual void compile_body();
virtual void compile_and_send_body();
virtual void next_stage();

View File

@ -14,6 +14,12 @@ void DRequest::remove_cookie(const std::string &key) {
_removed_cookies.push_back(key);
}
HTTPMethod DRequest::get_method() const {
//the enums are in the same order
return static_cast<HTTPMethod>(static_cast<int>(request->getMethod()));
}
void DRequest::send() {
//if (connection_closed) {
// DRequestPool::return_request(this);

View File

@ -24,6 +24,8 @@ public:
void add_cookie(const ::Cookie &cookie);
void remove_cookie(const std::string &key);
HTTPMethod get_method() const;
void send();
void send_file(const std::string &p_file_path);
void reset();