File tree Expand file tree Collapse file tree
include/boost/http_proto/server Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1616namespace boost {
1717namespace http_proto {
1818
19+ struct route_params ;
20+
1921/* * A router for HTTP servers
2022
2123 This is a specialization of `basic_router` using
Original file line number Diff line number Diff line change @@ -299,6 +299,20 @@ class basic_router;
299299class route_params_base
300300{
301301public:
302+ /* * Return true if the request method matches `m`
303+ */
304+ bool is_method (
305+ http_proto::method m) const noexcept
306+ {
307+ return verb_ == m;
308+ }
309+
310+ /* * Return true if the request method matches `s`
311+ */
312+ BOOST_HTTP_PROTO_DECL
313+ bool is_method (
314+ core::string_view s) const noexcept ;
315+
302316 /* * The mount path of the current router
303317
304318 This is the portion of the request path
Original file line number Diff line number Diff line change 88//
99
1010#include < boost/http_proto/server/router_types.hpp>
11+ #include < boost/url/grammar/ci_string.hpp>
1112#include < boost/assert.hpp>
1213#include < cstring>
1314
@@ -78,5 +79,16 @@ do_detach()
7879 detail::throw_logic_error ();
7980}
8081
82+ bool
83+ route_params_base::
84+ is_method (
85+ core::string_view s) const noexcept
86+ {
87+ auto m = http_proto::string_to_method (s);
88+ if (m != http_proto::method::unknown)
89+ return verb_ == m;
90+ return s == verb_str_;
91+ }
92+
8193} // http_proto
8294} // boost
Original file line number Diff line number Diff line change 11//
2- // Copyright (c) 2025 Vinnie Falco (vinnie dot falco at gmail dot com)
2+ // Copyright (c) 2025 Vinnie Falco (vinnie. falco@ gmail. com)
33//
44// Distributed under the Boost Software License, Version 1.0. (See accompanying
55// file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
99
1010// Test that header file is self-contained.
1111#include < boost/http_proto/server/router_types.hpp>
12+ #include < boost/http_proto/server/router.hpp>
13+
14+ #include " test_suite.hpp"
15+
16+ namespace boost {
17+ namespace http_proto {
18+
19+ struct router_types_test
20+ {
21+ void
22+ run ()
23+ {
24+ basic_router<route_params_base> r;
25+ r.add (http_proto::method::post , " /" ,
26+ [](route_params_base& rp) ->
27+ route_result
28+ {
29+ BOOST_TEST ( rp.is_method (http_proto::method::post ));
30+ BOOST_TEST (! rp.is_method (http_proto::method::get));
31+ BOOST_TEST (! rp.is_method (" GET" ));
32+ BOOST_TEST (! rp.is_method (" Post" ));
33+ BOOST_TEST ( rp.is_method (" POST" ));
34+ return route::send;
35+ });
36+ route_params_base rp;
37+ auto rv = r.dispatch (" POST" , " /" , rp);
38+ BOOST_TEST (rv = route::send);
39+ }
40+ };
41+
42+ TEST_SUITE (
43+ router_types_test,
44+ " boost.http_proto.server.router_types" );
45+
46+ } // http_proto
47+ } // boost
You can’t perform that action at this time.
0 commit comments