MySQL 9.4.0
Source Code Documentation
url_paths.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2024, 2025, 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_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_URL_PATHS_H_
27#define ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_URL_PATHS_H_
28
29#include <string>
30#include <vector>
31
33#include "http/base/uri.h"
35
36namespace mrs {
37namespace endpoint {
38namespace handler {
39
40const std::string k_openapi_catalog = "/open-api-catalog";
41const std::string k_path_metadata_catalog = "metadata-catalog";
42const std::string k_metadata = "_metadata";
43const std::string k_debug = "_debug";
44
45inline auto path_schema_catalog(const std::string &service_schema_path) {
46 using namespace std::string_literals;
47
48 return ::http::base::UriPathMatcher{
49 service_schema_path + "/"s + k_path_metadata_catalog, false, true};
50}
51
53 auto u = uri;
54 u.get_path_elements().push_back(k_path_metadata_catalog);
55 return u.join();
56}
57
58inline auto path_service_debug(const std::string &service_path) {
59 using namespace std::string_literals;
60
61 return ::http::base::UriPathMatcher{service_path + "/"s + k_debug, false,
62 true};
63}
64
65inline auto path_service_metadata(const std::string &service_path) {
66 using namespace std::string_literals;
67
68 return ::http::base::UriPathMatcher{service_path + "/"s + k_metadata, false,
69 true};
70}
71
72inline auto path_schema_metadata(const std::string &service_schema_path) {
73 using namespace std::string_literals;
74
75 return ::http::base::UriPathMatcher{service_schema_path + "/"s + k_metadata,
76 false, true};
77}
78
79inline auto path_object_metadata(const std::string &service_schema_path,
80 const std::string &obj_name) {
81 using namespace std::string_literals;
82
83 return ::http::base::UriPathMatcher{
84 service_schema_path + obj_name + "/"s + k_metadata, false, true};
85}
86
87inline auto path_obj_openapi_swagger(const std::string &service_schema_path,
88 const std::string &obj_name) {
89 using namespace std::string_literals;
90
91 return ::http::base::UriPathMatcher{
92 service_schema_path + k_openapi_catalog + obj_name, false, true};
93}
94
96 const std::string &service_schema_path) {
97 using namespace std::string_literals;
98
99 return ::http::base::UriPathMatcher{service_schema_path + k_openapi_catalog,
100 false, true};
101}
102
103inline auto path_schema_openapi_swagger_alias(const std::string &service_name,
104 const std::string &schema_name) {
105 using namespace std::string_literals;
106
107 return ::http::base::UriPathMatcher{
108 "/"s + service_name + k_openapi_catalog + "/" + schema_name, false, true};
109}
110
111inline auto path_service_openapi_swagger(const std::string &service_path) {
112 using namespace std::string_literals;
113
114 return ::http::base::UriPathMatcher{service_path + k_openapi_catalog, false,
115 true};
116}
117
118inline auto path_db_object_with_index(const std::string &object_path,
119 const std::string &service_schema_path,
120 const bool is_index) {
121 using namespace std::string_literals;
122 std::vector<::http::base::UriPathMatcher> result{{object_path, true, false}};
123
124 if (is_index) {
125 // When the url path is empty, its root path, which
126 // http plugin processes as "", instead "/".
127 if (service_schema_path.empty())
128 result.emplace_back(service_schema_path, false, false);
129 else
130 result.emplace_back(service_schema_path + "/", false, false);
131 }
132
133 return result;
134}
135
136inline auto path_file(std::string service_schema_path,
137 const std::string &object_path, bool is_index) {
138 using namespace std::string_literals;
139 std::vector<::http::base::UriPathMatcher> result{
140 {service_schema_path + object_path, false, false}};
141
142 if (is_index) {
143 // When the url path is empty, it's root path, which
144 // http plugin processes as "", instead "/".
145 if (service_schema_path.empty())
146 result.emplace_back(service_schema_path, false, false);
147 else
148 result.emplace_back(service_schema_path + "/", false, false);
149 }
150
151 return result;
152}
153
154inline std::string remove_leading_slash_from_path(const std::string &path) {
155 if (path.empty()) return {};
156 if (path[0] == '/') return path.substr(1);
157 return {};
158}
159
160inline auto path_content_file(const std::string &service_schema_path) {
161 return path_file(service_schema_path, "",
162 helper::ends_with(service_schema_path, "/index.html"));
163}
164
165} // namespace handler
166} // namespace endpoint
167} // namespace mrs
168
169#endif /* ROUTER_SRC_MYSQL_REST_SERVICE_SRC_MRS_ENDPOINT_HANDLER_URL_PATHS_H_ \
170 */
The handler class is the interface for dynamically loadable storage engines.
Definition: handler.h:4666
static char * path
Definition: mysqldump.cc:150
bool ends_with(const std::string &value, const std::string &sst)
Definition: contains.h:67
Request::Uri Uri
Definition: request.cc:36
std::string url_sch_metadata_catalog(const ::http::base::Uri &uri)
Definition: url_paths.h:52
auto path_service_metadata(const std::string &service_path)
Definition: url_paths.h:65
auto path_schema_metadata(const std::string &service_schema_path)
Definition: url_paths.h:72
auto path_db_object_with_index(const std::string &object_path, const std::string &service_schema_path, const bool is_index)
Definition: url_paths.h:118
const std::string k_openapi_catalog
Definition: url_paths.h:40
auto path_obj_openapi_swagger(const std::string &service_schema_path, const std::string &obj_name)
Definition: url_paths.h:87
const std::string k_path_metadata_catalog
Definition: url_paths.h:41
const std::string k_debug
Definition: url_paths.h:43
auto path_schema_openapi_swagger(const std::string &service_schema_path)
Definition: url_paths.h:95
const std::string k_metadata
Definition: url_paths.h:42
auto path_service_debug(const std::string &service_path)
Definition: url_paths.h:58
std::string remove_leading_slash_from_path(const std::string &path)
Definition: url_paths.h:154
auto path_schema_openapi_swagger_alias(const std::string &service_name, const std::string &schema_name)
Definition: url_paths.h:103
auto path_schema_catalog(const std::string &service_schema_path)
Definition: url_paths.h:45
auto path_service_openapi_swagger(const std::string &service_path)
Definition: url_paths.h:111
auto path_object_metadata(const std::string &service_schema_path, const std::string &obj_name)
Definition: url_paths.h:79
auto path_content_file(const std::string &service_schema_path)
Definition: url_paths.h:160
auto path_file(std::string service_schema_path, const std::string &object_path, bool is_index)
Definition: url_paths.h:136
Definition: authorize_manager.h:48
struct result result
Definition: result.h:34
Definition: result.h:30