From abb3dec700d019c370ed175f7c833e80610280ae Mon Sep 17 00:00:00 2001 From: Veloman Yunkan Date: Mon, 13 Apr 2020 00:00:37 +0400 Subject: [PATCH] Refactoring: extracted str2RequestMethod() --- src/server/request_context.cpp | 42 +++++++++++++++------------------- 1 file changed, 19 insertions(+), 23 deletions(-) diff --git a/src/server/request_context.cpp b/src/server/request_context.cpp index 0dd3114d2..54d39b808 100644 --- a/src/server/request_context.cpp +++ b/src/server/request_context.cpp @@ -30,42 +30,38 @@ namespace kiwix { static std::atomic_ullong s_requestIndex(0); +namespace { + +RequestMethod str2RequestMethod(const std::string& method) { + if (method == "GET") return RequestMethod::GET; + else if (method == "HEAD") return RequestMethod::HEAD; + else if (method == "POST") return RequestMethod::POST; + else if (method == "PUT") return RequestMethod::PUT; + else if (method == "DELETE") return RequestMethod::DELETE_; + else if (method == "CONNECT") return RequestMethod::CONNECT; + else if (method == "OPTIONS") return RequestMethod::OPTIONS; + else if (method == "TRACE") return RequestMethod::TRACE; + else if (method == "PATCH") return RequestMethod::PATCH; + else return RequestMethod::OTHER; +} + +} // unnamed namespace + RequestContext::RequestContext(struct MHD_Connection* connection, std::string rootLocation, const std::string& _url, - const std::string& method, + const std::string& _method, const std::string& version) : full_url(_url), url(_url), valid_url(true), + method(str2RequestMethod(_method)), version(version), requestIndex(s_requestIndex++), acceptEncodingDeflate(false), accept_range(false), range_pair(0, -1) { - if (method == "GET") { - this->method = RequestMethod::GET; - } else if (method == "HEAD") { - this->method = RequestMethod::HEAD; - } else if (method == "POST") { - this->method = RequestMethod::POST; - } else if (method == "PUT") { - this->method = RequestMethod::PUT; - } else if (method == "DELETE") { - this->method = RequestMethod::DELETE_; - } else if (method == "CONNECT") { - this->method = RequestMethod::CONNECT; - } else if (method == "OPTIONS") { - this->method = RequestMethod::OPTIONS; - } else if (method == "TRACE") { - this->method = RequestMethod::TRACE; - } else if (method == "PATCH") { - this->method = RequestMethod::PATCH; - } else { - this->method = RequestMethod::OTHER; - } - MHD_get_connection_values(connection, MHD_HEADER_KIND, &RequestContext::fill_header, this); MHD_get_connection_values(connection, MHD_GET_ARGUMENT_KIND, &RequestContext::fill_argument, this);