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