libs/http/src/server/detail/route_match.cpp
94.4% Lines (34/36)
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 dot falco at gmail dot 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 | namespace detail { | ||
| 16 | |||
| 17 | 179 | router_base:: | |
| 18 | matcher:: | ||
| 19 | matcher( | ||
| 20 | std::string_view pat, | ||
| 21 | 179 | bool end_arg) | |
| 22 |
1/1✓ Branch 2 taken 179 times.
|
179 | : decoded_pat_( |
| 23 | ✗ | [&pat] | |
| 24 | { | ||
| 25 |
2/2✓ Branch 1 taken 179 times.
✓ Branch 4 taken 179 times.
|
179 | auto s = pct_decode(pat); |
| 26 | 179 | if( s.size() > 1 | |
| 27 |
4/6✓ Branch 0 taken 136 times.
✓ Branch 1 taken 43 times.
✗ Branch 3 not taken.
✓ Branch 4 taken 136 times.
✗ Branch 5 not taken.
✓ Branch 6 taken 179 times.
|
179 | && s.back() == '/') |
| 28 | ✗ | s.pop_back(); | |
| 29 | 179 | return s; | |
| 30 |
1/1✓ Branch 1 taken 179 times.
|
358 | }()) |
| 31 | 179 | , end_(end_arg) | |
| 32 | 358 | , slash_(pat == "/") | |
| 33 | { | ||
| 34 |
2/2✓ Branch 0 taken 136 times.
✓ Branch 1 taken 43 times.
|
179 | if(! slash_) |
| 35 | { | ||
| 36 |
1/1✓ Branch 2 taken 136 times.
|
136 | auto rv = parse_route_pattern(decoded_pat_); |
| 37 |
2/2✓ Branch 1 taken 12 times.
✓ Branch 2 taken 124 times.
|
136 | if(rv.has_error()) |
| 38 | 12 | ec_ = rv.error(); | |
| 39 | else | ||
| 40 |
1/1✓ Branch 2 taken 124 times.
|
124 | pattern_ = std::move(rv.value()); |
| 41 | 136 | } | |
| 42 | 179 | } | |
| 43 | |||
| 44 | bool | ||
| 45 | 142 | router_base:: | |
| 46 | matcher:: | ||
| 47 | operator()( | ||
| 48 | route_params_base& p, | ||
| 49 | match_result& mr) const | ||
| 50 | { | ||
| 51 |
1/2✗ Branch 1 not taken.
✓ Branch 2 taken 142 times.
|
142 | BOOST_ASSERT(! p.path.empty()); |
| 52 | |||
| 53 | // Root pattern special case | ||
| 54 |
7/8✓ Branch 0 taken 40 times.
✓ Branch 1 taken 102 times.
✓ Branch 2 taken 22 times.
✓ Branch 3 taken 18 times.
✓ Branch 5 taken 22 times.
✗ Branch 6 not taken.
✓ Branch 7 taken 40 times.
✓ Branch 8 taken 102 times.
|
142 | if(slash_ && (!end_ || p.path == "/")) |
| 55 | { | ||
| 56 | 40 | mr.adjust_path(p, 0); | |
| 57 | 40 | return true; | |
| 58 | } | ||
| 59 | |||
| 60 | // Convert bitflags to match_options | ||
| 61 | match_options opts{ | ||
| 62 | 102 | p.case_sensitive, | |
| 63 | 102 | p.strict, | |
| 64 | 102 | end_ | |
| 65 | 102 | }; | |
| 66 | |||
| 67 |
1/1✓ Branch 1 taken 102 times.
|
102 | auto rv = match_route(p.path, pattern_, opts); |
| 68 |
2/2✓ Branch 1 taken 15 times.
✓ Branch 2 taken 87 times.
|
102 | if(rv.has_error()) |
| 69 | 15 | return false; | |
| 70 | |||
| 71 | 87 | auto const n = rv->matched_length; | |
| 72 | 87 | mr.adjust_path(p, n); | |
| 73 | 87 | mr.params_ = std::move(rv->params); | |
| 74 | 87 | return true; | |
| 75 | 102 | } | |
| 76 | |||
| 77 | } // detail | ||
| 78 | } // http | ||
| 79 | } // boost | ||
| 80 |