diff --git a/modules/web/http_server_simple/http_parser.cpp b/modules/web/http_server_simple/http_parser.cpp index e3a476a8b..534a7961b 100644 --- a/modules/web/http_server_simple/http_parser.cpp +++ b/modules/web/http_server_simple/http_parser.cpp @@ -299,6 +299,34 @@ int HTTPParser::on_message_begin() { _request.instance(); + switch (parser->method) { + case http_method::HTTP_DELETE: + _request->set_method(HTTPServerEnums::HTTP_METHOD_DELETE); + break; + case http_method::HTTP_GET: + _request->set_method(HTTPServerEnums::HTTP_METHOD_GET); + break; + case http_method::HTTP_HEAD: + _request->set_method(HTTPServerEnums::HTTP_METHOD_HEAD); + break; + case http_method::HTTP_POST: + _request->set_method(HTTPServerEnums::HTTP_METHOD_POST); + break; + case http_method::HTTP_PUT: + _request->set_method(HTTPServerEnums::HTTP_METHOD_PUT); + break; + case http_method::HTTP_OPTIONS: + _request->set_method(HTTPServerEnums::HTTP_METHOD_OPTIONS); + break; + case http_method::HTTP_PATCH: + _request->set_method(HTTPServerEnums::HTTP_METHOD_PATCH); + break; + default: + //TODO close the connection + _request->set_method(HTTPServerEnums::HTTP_METHOD_INVALID); + break; + } + #if MESSAGE_DEBUG ERR_PRINT("begin"); #endif diff --git a/modules/web/http_server_simple/simple_web_server_request.cpp b/modules/web/http_server_simple/simple_web_server_request.cpp index 26d154792..86ba022f9 100644 --- a/modules/web/http_server_simple/simple_web_server_request.cpp +++ b/modules/web/http_server_simple/simple_web_server_request.cpp @@ -24,7 +24,7 @@ String SimpleWebServerRequest::get_cookie(const String &key) { } HTTPServerEnums::HTTPMethod SimpleWebServerRequest::get_method() const { - return HTTPServerEnums::HTTP_METHOD_GET; + return _method; } void SimpleWebServerRequest::parse_files() { @@ -136,8 +136,13 @@ void SimpleWebServerRequest::add_cookie_data(const String &key, const String &va _cookies.push_back(d); } +void SimpleWebServerRequest::set_method(const HTTPServerEnums::HTTPMethod method) { + _method = method; +} + SimpleWebServerRequest::SimpleWebServerRequest() { _server = nullptr; + _method = HTTPServerEnums::HTTP_METHOD_GET; } SimpleWebServerRequest::~SimpleWebServerRequest() { diff --git a/modules/web/http_server_simple/simple_web_server_request.h b/modules/web/http_server_simple/simple_web_server_request.h index cf6ef5686..5dd9ea126 100644 --- a/modules/web/http_server_simple/simple_web_server_request.h +++ b/modules/web/http_server_simple/simple_web_server_request.h @@ -49,6 +49,8 @@ public: void add_cookie_data(const String &key, const String &value); + void set_method(const HTTPServerEnums::HTTPMethod method); + //virtual String get_path_full() const; SimpleWebServerRequest(); @@ -77,6 +79,7 @@ protected: }; Vector _cookies; + HTTPServerEnums::HTTPMethod _method; }; #endif