libs/http/src/server/detail/route_match.cpp

94.6% Lines (35/37) 100.0% Functions (3/3) 86.2% Branches (25/29)
libs/http/src/server/detail/route_match.cpp
Line Branch Hits Source Code
1 //
2 // Copyright (c) 2025 Vinnie Falco (vinnie.falco@gmail.com)
3 //
4 // Distributed under the Boost Software License, Version 1.0. (See accompanying
5 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt)
6 //
7 // Official repository: https://github.com/cppalliance/http
8 //
9
10 #include "src/server/detail/pct_decode.hpp"
11 #include "src/server/detail/route_match.hpp"
12
13 namespace boost {
14 namespace http {
15
16 278 detail::router_base::
17 matcher::
18 matcher(
19 std::string_view pat,
20 278 bool end_arg)
21
1/1
✓ Branch 2 taken 278 times.
278 : decoded_pat_(
22 [&pat]
23 {
24
2/2
✓ Branch 1 taken 278 times.
✓ Branch 4 taken 278 times.
278 auto s = detail::pct_decode(pat);
25 278 if( s.size() > 1
26
4/6
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 98 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 180 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 278 times.
278 && s.back() == '/')
27 s.pop_back();
28 278 return s;
29
1/1
✓ Branch 1 taken 278 times.
556 }())
30 278 , end_(end_arg)
31 556 , slash_(pat == "/")
32 {
33
2/2
✓ Branch 0 taken 180 times.
✓ Branch 1 taken 98 times.
278 if(! slash_)
34 {
35
1/1
✓ Branch 2 taken 180 times.
180 auto rv = parse_route_pattern(decoded_pat_);
36
2/2
✓ Branch 1 taken 12 times.
✓ Branch 2 taken 168 times.
180 if(rv.has_error())
37 12 ec_ = rv.error();
38 else
39
1/1
✓ Branch 2 taken 168 times.
168 pattern_ = std::move(rv.value());
40 180 }
41 278 }
42
43 bool
44 336 detail::router_base::
45 matcher::
46 operator()(
47 route_params& p,
48 match_result& mr) const
49 {
50
1/2
✗ Branch 1 not taken.
✓ Branch 2 taken 336 times.
336 BOOST_ASSERT(! p.path.empty());
51
52 // Root pattern special case
53
7/8
✓ Branch 0 taken 132 times.
✓ Branch 1 taken 204 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 110 times.
✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 132 times.
✓ Branch 8 taken 204 times.
336 if(slash_ && (!end_ || p.path == "/"))
54 {
55 132 mr.adjust_path(p, 0);
56 132 return true;
57 }
58
59 // Convert bitflags to match_options
60 204 auto& pv = *detail::route_params_access{p};
61 detail::match_options opts{
62 204 pv.case_sensitive,
63 204 pv.strict,
64 204 end_
65 204 };
66
67
1/1
✓ Branch 1 taken 204 times.
204 auto rv = match_route(p.path, pattern_, opts);
68
2/2
✓ Branch 1 taken 39 times.
✓ Branch 2 taken 165 times.
204 if(rv.has_error())
69 39 return false;
70
71 165 auto const n = rv->matched_length;
72 165 mr.adjust_path(p, n);
73 165 mr.params_ = std::move(rv->params);
74 165 return true;
75 204 }
76
77 } // http
78 } // boost
79