mirror of
https://gitee.com/an-tao/drogon.git
synced 2024-12-02 03:38:03 +08:00
Added isHead() method to HttpRequest, to preserve information about the original method for use in the controller (#1743)
This commit is contained in:
parent
81bf767d89
commit
40579ae308
@ -123,6 +123,16 @@ class DROGON_EXPORT HttpRequest
|
||||
return method();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Check if the method is or was HttpMethod::Head
|
||||
* @details Allows to know that an incoming request is a HEAD request, since
|
||||
* drogon sets the method to HttpMethod::Get before calling the
|
||||
* controller
|
||||
* @return true if method() returns HttpMethod::Head, or HttpMethod::Get but
|
||||
* was previously HttpMethod::Head
|
||||
*/
|
||||
virtual bool isHead() const = 0;
|
||||
|
||||
/// Get the header string identified by the key parameter.
|
||||
/**
|
||||
* @note
|
||||
|
@ -55,6 +55,7 @@ class HttpRequestImpl : public HttpRequest
|
||||
void reset()
|
||||
{
|
||||
method_ = Invalid;
|
||||
previousMethod_ = Invalid;
|
||||
version_ = Version::kUnknown;
|
||||
flagForParsingJson_ = false;
|
||||
headers_.clear();
|
||||
@ -110,6 +111,7 @@ class HttpRequestImpl : public HttpRequest
|
||||
|
||||
void setMethod(const HttpMethod method) override
|
||||
{
|
||||
previousMethod_ = method_;
|
||||
method_ = method;
|
||||
return;
|
||||
}
|
||||
@ -119,6 +121,13 @@ class HttpRequestImpl : public HttpRequest
|
||||
return method_;
|
||||
}
|
||||
|
||||
bool isHead() const override
|
||||
{
|
||||
return (method_ == HttpMethod::Head) ||
|
||||
((method_ == HttpMethod::Get) &&
|
||||
(previousMethod_ == HttpMethod::Head));
|
||||
}
|
||||
|
||||
const char *methodString() const override;
|
||||
|
||||
void setPath(const char *start, const char *end)
|
||||
@ -576,6 +585,7 @@ class HttpRequestImpl : public HttpRequest
|
||||
mutable bool flagForParsingParameters_{false};
|
||||
mutable bool flagForParsingJson_{false};
|
||||
HttpMethod method_{Invalid};
|
||||
HttpMethod previousMethod_{Invalid};
|
||||
Version version_{Version::kUnknown};
|
||||
std::string path_;
|
||||
std::string originalPath_;
|
||||
|
Loading…
Reference in New Issue
Block a user