@@ -55,6 +55,18 @@ void expresso::core::Server::listen(int port, std::function<void()> callback) {
5555 return ;
5656}
5757
58+ mochios::enums::method expresso::core::Server::getMethodFromString (const std::string &method) noexcept (false ) {
59+ if (method == " GET" ) return mochios::enums::method::GET;
60+ else if (method == " POST" ) return mochios::enums::method::POST;
61+ else if (method == " PUT" ) return mochios::enums::method::PUT;
62+ else if (method == " PATCH" ) return mochios::enums::method::PATCH;
63+ else if (method == " DELETE" ) return mochios::enums::method::DELETE;
64+ else if (method == " OPTIONS" ) return mochios::enums::method::OPTIONS;
65+ else if (method == " HEAD" ) return mochios::enums::method::HEAD;
66+ else logger::error (" Unsupported HTTP method: " + method,
67+ " expresso::core::Server::getMethodFromString(std::string &method) noexcept(false)" );
68+ }
69+
5870void expresso::core::Server::setupMiddlewares () {
5971 this ->use (std::make_unique<expresso::middleware::Version>());
6072 this ->use (std::make_unique<expresso::middleware::Date>());
@@ -136,17 +148,8 @@ expresso::core::Server::makeRequest(std::string &request) noexcept(false) {
136148
137149 std::vector<std::string> parts = brewtils::string::split (line, " " );
138150 const std::string method = brewtils::string::upper (parts[0 ]);
139- std::set<std::string>::const_iterator methodIter =
140- mochios::enums::methods.find (method);
141- if (methodIter == mochios::enums::methods.end ()) {
142- logger::error (" Unsupported HTTP method: " + method,
143- " expresso::core::Server::makeRequest(std::string &request) "
144- " noexcept(false)" );
145- }
146-
147151 expresso::messages::Request req (parts[1 ]);
148- req.method = static_cast <mochios::enums::method>(
149- std::distance (mochios::enums::methods.begin (), methodIter) - 1 );
152+ req.method = this ->getMethodFromString (method);
150153 req.httpVersion = parts[2 ];
151154 if (req.httpVersion .substr (0 , 5 ) != " HTTP/" ) {
152155 logger::error (" Invalid HTTP version: " + req.httpVersion ,
0 commit comments