MySQL 9.1.0
Source Code Documentation
http_request_router.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2021, 2024, Oracle and/or its affiliates.
3
4 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License, version 2.0,
6 as published by the Free Software Foundation.
7
8 This program is designed to work with certain software (including
9 but not limited to OpenSSL) that is licensed under separate terms,
10 as designated in a particular file or component or in included license
11 documentation. The authors of MySQL hereby grant you an additional
12 permission to link the program and your derivative works with the
13 separately licensed software that they have either included with
14 the program or referenced in the documentation.
15
16 This program is distributed in the hope that it will be useful,
17 but WITHOUT ANY WARRANTY; without even the implied warranty of
18 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 GNU General Public License for more details.
20
21 You should have received a copy of the GNU General Public License
22 along with this program; if not, write to the Free Software
23 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
24*/
25
26#ifndef ROUTER_SRC_HTTP_SRC_HTTP_REQUEST_ROUTER_H_
27#define ROUTER_SRC_HTTP_SRC_HTTP_REQUEST_ROUTER_H_
28
29#include <unicode/regex.h>
30
31#include <memory>
32#include <shared_mutex>
33#include <string>
34#include <vector>
35
36#include "http/base/request.h"
41
44 public:
46 using BaseRequestHandlerPtr = std::shared_ptr<http::base::RequestHandler>;
47
48 void append(const std::string &url_regex_str,
49 std::unique_ptr<RequestHandler> cb);
50 void remove(const void *handler_id);
51 void remove(const std::string &url_regex_str);
52
53 void set_default_route(std::unique_ptr<RequestHandler> cb);
54 void clear_default_route();
55 void route(http::base::Request &req) override;
56
57 void require_realm(const std::string &realm) { require_realm_ = realm; }
58
59 private:
61 public:
62 RouteMatcher(std::string url_pattern, BaseRequestHandlerPtr handler)
63 : url_pattern_(std::move(url_pattern)), handler_(std::move(handler)) {}
64
66
67 stdx::expected<void, UErrorCode> matches(std::string_view input) const;
68
70 const icu::UnicodeString &input) const;
71
72 BaseRequestHandlerPtr handler() const { return handler_; }
73
74 const std::string &url_pattern() const { return url_pattern_; }
75
76 private:
77 std::string url_pattern_;
79
80 std::unique_ptr<icu::RegexPattern> regex_pattern_;
81 };
82
83 // if no routes are specified, return 404
84 void handler_not_found(http::base::Request &req);
85 BaseRequestHandlerPtr find_route_handler(std::string_view path);
86
87 std::vector<RouteMatcher> request_handlers_;
88
90 std::string require_realm_;
91
92 mutable std::shared_mutex route_mtx_;
93};
94
95#endif // ROUTER_SRC_HTTP_SRC_HTTP_REQUEST_ROUTER_H_
Definition: http_request_router.h:60
RouteMatcher(std::string url_pattern, BaseRequestHandlerPtr handler)
Definition: http_request_router.h:62
std::unique_ptr< icu::RegexPattern > regex_pattern_
Definition: http_request_router.h:80
const std::string & url_pattern() const
Definition: http_request_router.h:74
std::string url_pattern_
Definition: http_request_router.h:77
BaseRequestHandlerPtr handler_
Definition: http_request_router.h:78
BaseRequestHandlerPtr handler() const
Definition: http_request_router.h:72
Definition: http_request_router.h:43
std::shared_mutex route_mtx_
Definition: http_request_router.h:92
void require_realm(const std::string &realm)
Definition: http_request_router.h:57
std::shared_ptr< http::base::RequestHandler > BaseRequestHandlerPtr
Definition: http_request_router.h:46
std::string require_realm_
Definition: http_request_router.h:90
std::vector< RouteMatcher > request_handlers_
Definition: http_request_router.h:87
BaseRequestHandlerPtr default_route_
Definition: http_request_router.h:89
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4583
Definition: request_handler.h:36
Definition: request.h:44
Definition: request_handler_interface.h:36
virtual void route(http::base::Request &request)=0
Definition: expected.h:286
#define HTTP_SERVER_LIB_EXPORT
Definition: http_server_lib_export.h:15
static char * path
Definition: mysqldump.cc:149
static mysql_service_status_t remove(reference_caching_channel channel, const char *implementation_name) noexcept
Definition: component.cc:137
Definition: gcs_xcom_synode.h:64