From 543f1eed30821b7e972c6099c4d882633cf987b1 Mon Sep 17 00:00:00 2001 From: Relintai Date: Thu, 5 Aug 2021 17:11:13 +0200 Subject: [PATCH] Added http method support to the request class. --- core/http/http_enums.h | 15 +++++++++++++++ core/http/request.cpp | 4 ++++ core/http/request.h | 4 ++++ modules/drogon/request.cpp | 6 ++++++ modules/drogon/request.h | 2 ++ 5 files changed, 31 insertions(+) create mode 100644 core/http/http_enums.h diff --git a/core/http/http_enums.h b/core/http/http_enums.h new file mode 100644 index 0000000..c8c039e --- /dev/null +++ b/core/http/http_enums.h @@ -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 \ No newline at end of file diff --git a/core/http/request.cpp b/core/http/request.cpp index 96d4041..2623236 100644 --- a/core/http/request.cpp +++ b/core/http/request.cpp @@ -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); diff --git a/core/http/request.h b/core/http/request.h index 9c1fbe0..11f6513 100644 --- a/core/http/request.h +++ b/core/http/request.h @@ -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(); diff --git a/modules/drogon/request.cpp b/modules/drogon/request.cpp index 6881675..864400a 100644 --- a/modules/drogon/request.cpp +++ b/modules/drogon/request.cpp @@ -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(static_cast(request->getMethod())); +} + void DRequest::send() { //if (connection_closed) { // DRequestPool::return_request(this); diff --git a/modules/drogon/request.h b/modules/drogon/request.h index 3f8c61a..4f384d0 100644 --- a/modules/drogon/request.h +++ b/modules/drogon/request.h @@ -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();