mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 11:47:56 +08:00
Optimize the parseParameter() method
This commit is contained in:
parent
baa7ea6a0a
commit
70b0828c17
@ -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
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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());
|
||||
|
Loading…
Reference in New Issue
Block a user