Refactor treatment of request-method (API Change):

fix #397

method enum class is added to represent all known request methods.
Functions are provided to convert from strings to and from the method
enumeration.

The fields container is modified to also work with the enum.
This commit is contained in:
Vinnie Falco
2017-05-30 15:59:50 -07:00
parent 3ae76d0d00
commit 9a585a82d9
21 changed files with 737 additions and 79 deletions
+126
View File
@@ -0,0 +1,126 @@
//
// Copyright (c) 2013-2017 Vinnie Falco (vinnie dot falco at gmail dot com)
//
// Distributed under the Boost Software License, Version 1.0. (See accompanying
// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
//
// Test that header file is self-contained.
#include <beast/http/verb.hpp>
#include <beast/unit_test/suite.hpp>
namespace beast {
namespace http {
class verb_test
: public beast::unit_test::suite
{
public:
void
testVerb()
{
auto const good =
[&](verb v)
{
BEAST_EXPECT(string_to_verb(to_string(v)) == v);
};
good(verb::delete_);
good(verb::get);
good(verb::head);
good(verb::post);
good(verb::put);
good(verb::connect);
good(verb::options);
good(verb::trace);
good(verb::copy);
good(verb::lock);
good(verb::mkcol);
good(verb::move);
good(verb::propfind);
good(verb::proppatch);
good(verb::search);
good(verb::unlock);
good(verb::bind);
good(verb::rebind);
good(verb::unbind);
good(verb::acl);
good(verb::report);
good(verb::mkactivity);
good(verb::checkout);
good(verb::merge);
good(verb::msearch);
good(verb::notify);
good(verb::subscribe);
good(verb::unsubscribe);
good(verb::patch);
good(verb::purge);
good(verb::mkcalendar);
good(verb::link);
good(verb::unlink);
auto const bad =
[&](string_view s)
{
auto const v = string_to_verb(s);
BEAST_EXPECTS(! v, to_string(*v));
};
bad("AC_");
bad("BIN_");
bad("CHECKOU_");
bad("CONNEC_");
bad("COP_");
bad("DELET_");
bad("GE_");
bad("HEA_");
bad("LIN_");
bad("LOC_");
bad("M-SEARC_");
bad("MERG_");
bad("MKACTIVIT_");
bad("MKCALENDA_");
bad("MKCO_");
bad("MOV_");
bad("NOTIF_");
bad("OPTION_");
bad("PATC_");
bad("POS_");
bad("PROPFIN_");
bad("PROPPATC_");
bad("PURG_");
bad("PU_");
bad("REBIN_");
bad("REPOR_");
bad("SEARC_");
bad("SUBSCRIB_");
bad("TRAC_");
bad("UNBIN_");
bad("UNLIN_");
bad("UNLOC_");
bad("UNSUBSCRIB_");
try
{
to_string(static_cast<verb>(-1));
fail("", __FILE__, __LINE__);
}
catch(std::exception const&)
{
pass();
}
}
void
run()
{
testVerb();
}
};
BEAST_DEFINE_TESTSUITE(verb,http,beast);
} // http
} // beast