mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
HttpRequest: add feature to avoid url encoding of path (#730)
This commit is contained in:
parent
ef51951785
commit
af2bd6ba69
@ -326,6 +326,16 @@ class HttpRequest
|
||||
/// Set the path of the request
|
||||
virtual void setPath(const std::string &path) = 0;
|
||||
|
||||
/**
|
||||
* @brief The default behavior is to encode the value of setPath
|
||||
* using urlEncode. Setting the path encode to false avoid the
|
||||
* value of path will be changed by the library
|
||||
*
|
||||
* @param bool true --> the path will be url encoded
|
||||
* false --> using value of path as it is set
|
||||
*/
|
||||
virtual void setPathEncode(bool) = 0;
|
||||
|
||||
/// Set the parameter of the request
|
||||
virtual void setParameter(const std::string &key,
|
||||
const std::string &value) = 0;
|
||||
|
@ -194,7 +194,14 @@ void HttpRequestImpl::appendToBuffer(trantor::MsgBuffer *output) const
|
||||
|
||||
if (!path_.empty())
|
||||
{
|
||||
output->append(utils::urlEncode(path_));
|
||||
if (pathEncode_)
|
||||
{
|
||||
output->append(utils::urlEncode(path_));
|
||||
}
|
||||
else
|
||||
{
|
||||
output->append(path_);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -508,6 +515,7 @@ void HttpRequestImpl::swap(HttpRequestImpl &that) noexcept
|
||||
swap(flagForParsingParameters_, that.flagForParsingParameters_);
|
||||
swap(matchedPathPattern_, that.matchedPathPattern_);
|
||||
swap(path_, that.path_);
|
||||
swap(pathEncode_, that.pathEncode_);
|
||||
swap(query_, that.query_);
|
||||
swap(headers_, that.headers_);
|
||||
swap(cookies_, that.cookies_);
|
||||
|
@ -51,6 +51,7 @@ class HttpRequestImpl : public HttpRequest
|
||||
cookies_.clear();
|
||||
flagForParsingParameters_ = false;
|
||||
path_.clear();
|
||||
pathEncode_ = true;
|
||||
matchedPathPattern_ = "";
|
||||
query_.clear();
|
||||
parameters_.clear();
|
||||
@ -121,6 +122,11 @@ class HttpRequestImpl : public HttpRequest
|
||||
path_ = path;
|
||||
}
|
||||
|
||||
void setPathEncode(bool pathEncode) override
|
||||
{
|
||||
pathEncode_ = pathEncode;
|
||||
}
|
||||
|
||||
virtual const std::unordered_map<std::string, std::string> ¶meters()
|
||||
const override
|
||||
{
|
||||
@ -488,6 +494,7 @@ class HttpRequestImpl : public HttpRequest
|
||||
HttpMethod method_{Invalid};
|
||||
Version version_{Version::kUnknown};
|
||||
std::string path_;
|
||||
bool pathEncode_{true};
|
||||
string_view matchedPathPattern_{""};
|
||||
std::string query_;
|
||||
std::unordered_map<std::string, std::string> headers_;
|
||||
|
Loading…
Reference in New Issue
Block a user