src/server/detail/route_match.cpp
94.6% Lines (35/37)
100.0% Functions (3/3)
| Line | TLA | Hits | Source Code |
|---|---|---|---|
| 1 | // | ||
| 2 | // Copyright (c) 2025 Vinnie Falco ([email protected]) | ||
| 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 | 192 | detail::router_base:: | |
| 17 | matcher:: | ||
| 18 | matcher( | ||
| 19 | std::string_view pat, | ||
| 20 | 192 | bool end_arg) | |
| 21 | 192 | : decoded_pat_( | |
| 22 | ✗ | [&pat] | |
| 23 | { | ||
| 24 | 192 | auto s = detail::pct_decode(pat); | |
| 25 | 192 | if( s.size() > 1 | |
| 26 | 192 | && s.back() == '/') | |
| 27 | ✗ | s.pop_back(); | |
| 28 | 192 | return s; | |
| 29 | 384 | }()) | |
| 30 | 192 | , end_(end_arg) | |
| 31 | 384 | , slash_(pat == "/") | |
| 32 | { | ||
| 33 | 192 | if(! slash_) | |
| 34 | { | ||
| 35 | 136 | auto rv = parse_route_pattern(decoded_pat_); | |
| 36 | 136 | if(rv.has_error()) | |
| 37 | 12 | ec_ = rv.error(); | |
| 38 | else | ||
| 39 | 124 | pattern_ = std::move(rv.value()); | |
| 40 | 136 | } | |
| 41 | 192 | } | |
| 42 | |||
| 43 | bool | ||
| 44 | 151 | detail::router_base:: | |
| 45 | matcher:: | ||
| 46 | operator()( | ||
| 47 | route_params& p, | ||
| 48 | match_result& mr) const | ||
| 49 | { | ||
| 50 | 151 | BOOST_ASSERT(! p.path.empty()); | |
| 51 | |||
| 52 | // Root pattern special case | ||
| 53 | 151 | if(slash_ && (!end_ || p.path == "/")) | |
| 54 | { | ||
| 55 | 49 | mr.adjust_path(p, 0); | |
| 56 | 49 | return true; | |
| 57 | } | ||
| 58 | |||
| 59 | // Convert bitflags to match_options | ||
| 60 | 102 | auto& pv = *detail::route_params_access{p}; | |
| 61 | detail::match_options opts{ | ||
| 62 | 102 | pv.case_sensitive, | |
| 63 | 102 | pv.strict, | |
| 64 | 102 | end_ | |
| 65 | 102 | }; | |
| 66 | |||
| 67 | 102 | auto rv = match_route(p.path, pattern_, opts); | |
| 68 | 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 | } // http | ||
| 78 | } // boost | ||
| 79 |