src/server/detail/route_match.cpp
94.6% Lines (35/37)
100.0% List of functions (3/3)
Functions (3)
Function
Calls
Lines
Blocks
boost::http::detail::router_base::matcher::matcher(std::basic_string_view<char, std::char_traits<char> >, bool)
:16
192x
100.0%
62.0%
boost::http::detail::router_base::matcher::matcher(std::basic_string_view<char, std::char_traits<char> >, bool)::{lambda()#1}::operator()() const
:22
192x
87.5%
85.0%
boost::http::detail::router_base::matcher::operator()(boost::http::route_params&, boost::http::route_params::match_result&) const
:44
151x
100.0%
90.0%
| Line | TLA | 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 | 192x | detail::router_base:: | |
| 17 | matcher:: | ||
| 18 | matcher( | ||
| 19 | std::string_view pat, | ||
| 20 | 192x | bool end_arg) | |
| 21 | 192x | : decoded_pat_( | |
| 22 | ✗ | [&pat] | |
| 23 | { | ||
| 24 | 192x | auto s = detail::pct_decode(pat); | |
| 25 | 192x | if( s.size() > 1 | |
| 26 | 192x | && s.back() == '/') | |
| 27 | ✗ | s.pop_back(); | |
| 28 | 192x | return s; | |
| 29 | 384x | }()) | |
| 30 | 192x | , end_(end_arg) | |
| 31 | 384x | , slash_(pat == "/") | |
| 32 | { | ||
| 33 | 192x | if(! slash_) | |
| 34 | { | ||
| 35 | 136x | auto rv = parse_route_pattern(decoded_pat_); | |
| 36 | 136x | if(rv.has_error()) | |
| 37 | 12x | ec_ = rv.error(); | |
| 38 | else | ||
| 39 | 124x | pattern_ = std::move(rv.value()); | |
| 40 | 136x | } | |
| 41 | 192x | } | |
| 42 | |||
| 43 | bool | ||
| 44 | 151x | detail::router_base:: | |
| 45 | matcher:: | ||
| 46 | operator()( | ||
| 47 | route_params& p, | ||
| 48 | match_result& mr) const | ||
| 49 | { | ||
| 50 | 151x | BOOST_ASSERT(! p.path.empty()); | |
| 51 | |||
| 52 | // Root pattern special case | ||
| 53 | 151x | if(slash_ && (!end_ || p.path == "/")) | |
| 54 | { | ||
| 55 | 49x | mr.adjust_path(p, 0); | |
| 56 | 49x | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | // Convert bitflags to match_options | ||
| 60 | 102x | auto& pv = *detail::route_params_access{p}; | |
| 61 | detail::match_options opts{ | ||
| 62 | 102x | pv.case_sensitive, | |
| 63 | 102x | pv.strict, | |
| 64 | 102x | end_ | |
| 65 | 102x | }; | |
| 66 | |||
| 67 | 102x | auto rv = match_route(p.path, pattern_, opts); | |
| 68 | 102x | if(rv.has_error()) | |
| 69 | 15x | return false; | |
| 70 | |||
| 71 | 87x | auto const n = rv->matched_length; | |
| 72 | 87x | mr.adjust_path(p, n); | |
| 73 | 87x | mr.params_ = std::move(rv->params); | |
| 74 | 87x | return true; | |
| 75 | 102x | } | |
| 76 | |||
| 77 | } // http | ||
| 78 | } // boost | ||
| 79 |