Refactor method and verb (API Change):

The verb interfaces now use verb::unknown instead of
boost::optional<verb> == boost::none to indicate that
the request-method is an unrecognized string.

The http::header interface is modified to focus more on the
verb enum rather than the string. For recognized verbs, the
implementation stores an integer instead of the string.
Unknown verbs are still stored as strings.

* header::method now returns a verb
* header::method_string returns the method text
This commit is contained in:
Vinnie Falco
2017-07-20 08:12:18 -07:00
parent d3049fa03b
commit 048ee7523c
15 changed files with 205 additions and 87 deletions
+39 -1
View File
@@ -22,6 +22,43 @@
namespace beast {
namespace http {
template<class Fields>
template<class>
string_view
header<true, Fields>::
get_method_string() const
{
if(method_ != verb::unknown)
return to_string(method_);
return fields.method_string();
}
template<class Fields>
template<class>
void
header<true, Fields>::
set_method(verb v)
{
if(v == verb::unknown)
BOOST_THROW_EXCEPTION(
std::invalid_argument{"unknown verb"});
method_ = v;
fields.method_string({});
}
template<class Fields>
template<class>
void
header<true, Fields>::
set_method(string_view s)
{
method_ = string_to_verb(s);
if(method_ != verb::unknown)
fields.method_string({});
else
fields.method_string(s);
}
template<class Fields>
void
swap(
@@ -31,6 +68,7 @@ swap(
using std::swap;
swap(m1.version, m2.version);
swap(m1.fields, m2.fields);
swap(m1.method_, m2.method_);
}
template<class Fields>
@@ -193,7 +231,7 @@ prepare(message<isRequest, Body, Fields>& msg,
{
using beast::detail::ci_equal;
if(*pi.content_length > 0 ||
ci_equal(msg.method(), "POST"))
msg.method() == verb::post)
{
msg.fields.insert(
"Content-Length", *pi.content_length);