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  
#ifndef BOOST_HTTP_SERVER_DETAIL_ROUTE_MATCH_HPP
10  
#ifndef BOOST_HTTP_SERVER_DETAIL_ROUTE_MATCH_HPP
11  
#define BOOST_HTTP_SERVER_DETAIL_ROUTE_MATCH_HPP
11  
#define BOOST_HTTP_SERVER_DETAIL_ROUTE_MATCH_HPP
12  

12  

13  
#include <boost/http/detail/config.hpp>
13  
#include <boost/http/detail/config.hpp>
14  
#include <boost/http/server/detail/router_base.hpp>
14  
#include <boost/http/server/detail/router_base.hpp>
15  
#include "src/server/route_abnf.hpp"
15  
#include "src/server/route_abnf.hpp"
16  
#include "src/server/detail/stable_string.hpp"
16  
#include "src/server/detail/stable_string.hpp"
17  
#include <cstdint>
17  
#include <cstdint>
18  
#include <string>
18  
#include <string>
19  
#include <vector>
19  
#include <vector>
20  

20  

21  
namespace boost {
21  
namespace boost {
22  
namespace http {
22  
namespace http {
23  

23  

24  
// Matches a path against a pattern
24  
// Matches a path against a pattern
25  
// Members ordered largest-to-smallest for optimal packing
25  
// Members ordered largest-to-smallest for optimal packing
26  
struct detail::router_base::matcher
26  
struct detail::router_base::matcher
27  
{
27  
{
28  
    matcher(std::string_view pat, bool end_);
28  
    matcher(std::string_view pat, bool end_);
29  

29  

30  
    // true if match
30  
    // true if match
31  
    bool operator()(
31  
    bool operator()(
32  
        route_params& p,
32  
        route_params& p,
33  
        match_result& mr) const;
33  
        match_result& mr) const;
34  

34  

35  
    // Returns error from pattern parsing, or empty if valid
35  
    // Returns error from pattern parsing, or empty if valid
36  
    system::error_code error() const noexcept { return ec_; }
36  
    system::error_code error() const noexcept { return ec_; }
37  

37  

38  
private:
38  
private:
39  
    friend class detail::router_base;
39  
    friend class detail::router_base;
40  
    friend struct detail::router_base::impl;
40  
    friend struct detail::router_base::impl;
41  

41  

42  
    system::error_code ec_;
42  
    system::error_code ec_;
43  
    std::string allow_header_;
43  
    std::string allow_header_;
44  
    detail::route_pattern pattern_;
44  
    detail::route_pattern pattern_;
45  
    std::vector<std::string> custom_verbs_;
45  
    std::vector<std::string> custom_verbs_;
46  

46  

47  
    // 16 bytes (pointer + size)
47  
    // 16 bytes (pointer + size)
48  
    detail::stable_string decoded_pat_;
48  
    detail::stable_string decoded_pat_;
49  

49  

50  
    // 8 bytes each
50  
    // 8 bytes each
51  
    std::size_t first_entry_ = 0;
51  
    std::size_t first_entry_ = 0;
52  
    std::size_t skip_ = 0;
52  
    std::size_t skip_ = 0;
53  
    std::uint64_t allowed_methods_ = 0;
53  
    std::uint64_t allowed_methods_ = 0;
54  

54  

55  
    // 4 bytes each
55  
    // 4 bytes each
56  
    opt_flags effective_opts_ = 0;
56  
    opt_flags effective_opts_ = 0;
57  
    opt_flags own_opts_ = 0;        // router's opt_flags (for re-parenting during inline)
57  
    opt_flags own_opts_ = 0;        // router's opt_flags (for re-parenting during inline)
58  
    std::uint32_t depth_ = 0;
58  
    std::uint32_t depth_ = 0;
59  

59  

60  
    // 1 byte each
60  
    // 1 byte each
61  
    bool end_;      // false for middleware
61  
    bool end_;      // false for middleware
62  
    bool slash_;
62  
    bool slash_;
63  
};
63  
};
64  

64  

65  
} // http
65  
} // http
66  
} // boost
66  
} // boost
67  

67  

68  
#endif
68  
#endif