Optimize the parseParameter() method

This commit is contained in:
antao 2019-01-04 17:30:37 +08:00
parent baa7ea6a0a
commit 70b0828c17
3 changed files with 21 additions and 12 deletions

View File

@ -17,12 +17,13 @@
#include <iostream>
using namespace drogon;
void HttpRequestImpl::parsePremeter()
void HttpRequestImpl::parseParameter()
{
std::string type = getHeaderBy("content-type");
std::transform(type.begin(), type.end(), type.begin(), tolower);
const std::string &input = query();
if(input.empty())
return;
std::string type = getHeaderBy("content-type");
std::transform(type.begin(), type.end(), type.begin(), tolower);
if (_method == Get || (_method == Post && (type == "" || type.find("application/x-www-form-urlencoded") != std::string::npos)))
{
@ -82,11 +83,11 @@ void HttpRequestImpl::parsePremeter()
_jsonPtr.reset();
}
}
LOG_TRACE << "_parameters:";
for (auto iter : _parameters)
{
LOG_TRACE << iter.first << "=" << iter.second;
}
// LOG_TRACE << "_parameters:";
// for (auto iter : _parameters)
// {
// LOG_TRACE << iter.first << "=" << iter.second;
// }
}
void HttpRequestImpl::appendToBuffer(MsgBuffer *output) const

View File

@ -50,7 +50,7 @@ class HttpRequestImpl : public HttpRequest
{
return _version;
}
void parsePremeter();
void parseParameter();
bool setMethod(const char *start, const char *end)
{
@ -135,7 +135,15 @@ class HttpRequestImpl : public HttpRequest
void setPath(const char *start, const char *end)
{
_path = urlDecode(std::string(start, end));
auto path = std::string(start, end);
if (path.find('+') != std::string::npos || path.find('%') != std::string::npos)
{
_path = urlDecode(path);
}
else
{
_path = path;
}
}
virtual void setPath(const std::string &path) override
{

View File

@ -113,7 +113,7 @@ void HttpServer::onMessage(const TcpConnectionPtr &conn,
if (context->gotAll())
{
context->requestImpl()->parsePremeter();
context->requestImpl()->parseParameter();
context->requestImpl()->setPeerAddr(conn->peerAddr());
context->requestImpl()->setLocalAddr(conn->localAddr());
context->requestImpl()->setReceiveDate(trantor::Date::date());