Add the getParameter() method into the HttpRequest class

This commit is contained in:
antao 2019-02-27 14:29:50 +08:00
parent 89cac562cf
commit 6d16877e7b
3 changed files with 13 additions and 2 deletions

View File

@ -85,6 +85,9 @@ class HttpRequest
/// Get parameters of the request.
virtual const std::unordered_map<std::string, std::string> &getParameters() const = 0;
/// Get a parameter identified by the @param key
virtual const std::string &getParameter(const std::string &key, const std::string &defaultVal = std::string()) const = 0;
/// Return the remote IP address and port
virtual const trantor::InetAddress &peerAddr() const = 0;

View File

@ -157,10 +157,18 @@ class HttpRequestImpl : public HttpRequest
_path = path;
}
const std::unordered_map<std::string, std::string> &getParameters() const override
virtual const std::unordered_map<std::string, std::string> &getParameters() const override
{
return _parameters;
}
virtual const std::string &getParameter(const std::string &key, const std::string &defaultVal = std::string()) const override
{
auto iter = _parameters.find(key);
if (iter != _parameters.end())
return iter->second;
return defaultVal;
}
const std::string &path() const override
{

View File

@ -39,7 +39,7 @@ const std::vector<HttpFile> &MultiPartParser::getFiles()
const std::map<std::string, std::string> &MultiPartParser::getParameters() const
{
return _parameters;
};
}
int MultiPartParser::parse(const HttpRequestPtr &req)
{