MySQL 9.0.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 <memory>
30#include <mutex>
31#include <regex>
32#include <string>
33#include <thread>
34#include <vector>
35
36#include "http/base/request.h"
41
43 public:
45 using BaseRequestHandlerPtr = std::shared_ptr<http::base::RequestHandler>;
46
47 public:
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);
55 void route(http::base::Request &req) override;
56
57 void require_realm(const std::string &realm) { require_realm_ = realm; }
58
59 private:
60 struct RouterData {
61 std::string url_regex_str;
62 std::regex url_regex;
64 };
65
66 // if no routes are specified, return 404
69
70 std::vector<RouterData> request_handlers_;
71
73 std::string require_realm_;
74
75 std::mutex route_mtx_;
76};
77
78#endif // ROUTER_SRC_HTTP_SRC_HTTP_REQUEST_ROUTER_H_
Definition: http_request_router.h:42
BaseRequestHandlerPtr find_route_handler(const std::string &path)
Definition: http_request_router.cc:148
void set_default_route(std::unique_ptr< RequestHandler > cb)
Definition: http_request_router.cc:98
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:45
void handler_not_found(http::base::Request &req)
Definition: http_request_router.cc:83
void clear_default_route()
Definition: http_request_router.cc:105
std::string require_realm_
Definition: http_request_router.h:73
void route(http::base::Request &req) override
Definition: http_request_router.cc:111
BaseRequestHandlerPtr default_route_
Definition: http_request_router.h:72
void remove(const void *handler_id)
Definition: http_request_router.cc:57
std::mutex route_mtx_
Definition: http_request_router.h:75
std::vector< RouterData > request_handlers_
Definition: http_request_router.h:70
void append(const std::string &url_regex_str, std::unique_ptr< RequestHandler > cb)
Request router.
Definition: http_request_router.cc:48
Definition: request_handler.h:36
Definition: request.h:44
Definition: request_handler_interface.h:34
static char * path
Definition: mysqldump.cc:149
Definition: http_request_router.h:60
BaseRequestHandlerPtr handler
Definition: http_request_router.h:63
std::regex url_regex
Definition: http_request_router.h:62
std::string url_regex_str
Definition: http_request_router.h:61