forked from boostorg/beast
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:
+8
-10
@@ -100,17 +100,15 @@ public:
|
||||
}
|
||||
|
||||
void
|
||||
testMethod()
|
||||
testMethodString()
|
||||
{
|
||||
f_t f;
|
||||
f.method(verb::get);
|
||||
BEAST_EXPECTS(f.method() == "GET", f.method());
|
||||
f.method("CRY");
|
||||
BEAST_EXPECTS(f.method() == "CRY", f.method());
|
||||
f.method("PUT");
|
||||
BEAST_EXPECTS(f.method() == "PUT", f.method());
|
||||
f.method("CONNECT");
|
||||
BEAST_EXPECTS(f.method() == "CONNECT", f.method());
|
||||
f.method_string("CRY");
|
||||
BEAST_EXPECTS(f.method_string() == "CRY", f.method_string());
|
||||
f.method_string("PUT");
|
||||
BEAST_EXPECTS(f.method_string() == "PUT", f.method_string());
|
||||
f.method_string({});
|
||||
BEAST_EXPECTS(f.method_string().empty(), f.method_string());
|
||||
}
|
||||
|
||||
void run() override
|
||||
@@ -118,7 +116,7 @@ public:
|
||||
testHeaders();
|
||||
testRFC2616();
|
||||
testErase();
|
||||
testMethod();
|
||||
testMethodString();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
+28
-2
@@ -137,8 +137,8 @@ public:
|
||||
m2.method("G");
|
||||
m2.body = "2";
|
||||
swap(m1, m2);
|
||||
BEAST_EXPECT(m1.method() == "G");
|
||||
BEAST_EXPECT(m2.method().empty());
|
||||
BEAST_EXPECT(m1.method_string() == "G");
|
||||
BEAST_EXPECT(m2.method_string().empty());
|
||||
BEAST_EXPECT(m1.target().empty());
|
||||
BEAST_EXPECT(m2.target() == "u");
|
||||
BEAST_EXPECT(m1.body == "2");
|
||||
@@ -296,6 +296,31 @@ public:
|
||||
}();
|
||||
}
|
||||
|
||||
void
|
||||
testMethod()
|
||||
{
|
||||
header<true> h;
|
||||
auto const vcheck =
|
||||
[&](verb v)
|
||||
{
|
||||
h.method(v);
|
||||
BEAST_EXPECT(h.method() == v);
|
||||
BEAST_EXPECT(h.method_string() == to_string(v));
|
||||
};
|
||||
auto const scheck =
|
||||
[&](string_view s)
|
||||
{
|
||||
h.method(s);
|
||||
BEAST_EXPECT(h.method() == string_to_verb(s));
|
||||
BEAST_EXPECT(h.method_string() == s);
|
||||
};
|
||||
vcheck(verb::get);
|
||||
vcheck(verb::head);
|
||||
scheck("GET");
|
||||
scheck("HEAD");
|
||||
scheck("XYZ");
|
||||
}
|
||||
|
||||
void
|
||||
run() override
|
||||
{
|
||||
@@ -305,6 +330,7 @@ public:
|
||||
testPrepare();
|
||||
testSwap();
|
||||
testSpecialMembers();
|
||||
testMethod();
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -237,7 +237,7 @@ public:
|
||||
[&](parser_type<true> const& p)
|
||||
{
|
||||
auto const& m = p.get();
|
||||
BEAST_EXPECT(m.method() == "GET");
|
||||
BEAST_EXPECT(m.method() == verb::get);
|
||||
BEAST_EXPECT(m.target() == "/");
|
||||
BEAST_EXPECT(m.version == 11);
|
||||
BEAST_EXPECT(! p.need_eof());
|
||||
@@ -274,7 +274,7 @@ public:
|
||||
BEAST_EXPECT(p.is_done());
|
||||
BEAST_EXPECT(p.is_header_done());
|
||||
BEAST_EXPECT(! p.need_eof());
|
||||
BEAST_EXPECT(m.method() == "GET");
|
||||
BEAST_EXPECT(m.method() == verb::get);
|
||||
BEAST_EXPECT(m.target() == "/");
|
||||
BEAST_EXPECT(m.version == 11);
|
||||
BEAST_EXPECT(m.fields["User-Agent"] == "test");
|
||||
|
||||
+3
-1
@@ -26,6 +26,8 @@ public:
|
||||
BEAST_EXPECT(string_to_verb(to_string(v)) == v);
|
||||
};
|
||||
|
||||
good(verb::unknown);
|
||||
|
||||
good(verb::delete_);
|
||||
good(verb::get);
|
||||
good(verb::head);
|
||||
@@ -64,7 +66,7 @@ public:
|
||||
[&](string_view s)
|
||||
{
|
||||
auto const v = string_to_verb(s);
|
||||
BEAST_EXPECTS(! v, to_string(*v));
|
||||
BEAST_EXPECTS(v == verb::unknown, to_string(v));
|
||||
};
|
||||
|
||||
bad("AC_");
|
||||
|
||||
Reference in New Issue
Block a user