MySQL 8.0.40
Source Code Documentation
http_server_component.h
Go to the documentation of this file.
1/*
2 Copyright (c) 2018, 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 MYSQLROUTER_HTTP_SERVER_COMPONENT_INCLUDED
27#define MYSQLROUTER_HTTP_SERVER_COMPONENT_INCLUDED
28
29#include <mutex>
30
33
34class HttpServer;
35
37 public:
38 void call(HttpRequest &req, void *me) {
39 auto *my = static_cast<BaseRequestHandler *>(me);
40 my->handle_request(req);
41 }
42
43 virtual void handle_request(HttpRequest &req) = 0;
44
45 BaseRequestHandler() = default;
46 explicit BaseRequestHandler(const BaseRequestHandler &) = delete;
49};
50
52 public:
53 static HttpServerComponent &get_instance();
54 void init(std::shared_ptr<HttpServer> srv);
55 void add_route(const std::string &url_regex,
56 std::unique_ptr<BaseRequestHandler> cb);
57 void remove_route(const std::string &url_regex);
58
59 private:
60 // disable copy, as we are a single-instance
62 void operator=(HttpServerComponent const &) = delete;
63
64 struct RouterData {
65 std::string url_regex_str;
66 std::unique_ptr<BaseRequestHandler> handler;
67 };
68
69 std::mutex rh_mu; // request handler mutex
70 std::vector<RouterData> request_handlers_;
71
72 std::weak_ptr<HttpServer> srv_;
73
75};
76
77class HttpAuthRealm;
78
79/**
80 * high-level Authentication frontend.
81 *
82 * bridges HttpRequest with the HttpAuthRealm's
83 */
85 public:
86 /**
87 * require Authorization.
88 *
89 * @returns if request has been handled
90 * @retval true request handled
91 */
92 static bool require_auth(HttpRequest &req,
93 std::shared_ptr<HttpAuthRealm> realm);
94};
95
96#endif
static mysql_service_status_t init()
Component initialization.
Definition: audit_api_message_emit.cc:571
Definition: http_server_component.h:36
BaseRequestHandler & operator=(const BaseRequestHandler &)=delete
void call(HttpRequest &req, void *me)
Definition: http_server_component.h:38
virtual void handle_request(HttpRequest &req)=0
BaseRequestHandler(const BaseRequestHandler &)=delete
BaseRequestHandler()=default
virtual ~BaseRequestHandler()
Authentication Realm.
Definition: http_auth_realm.h:47
high-level Authentication frontend.
Definition: http_server_component.h:84
a HTTP request and response.
Definition: http_request.h:453
Definition: http_server_component.h:51
std::mutex rh_mu
Definition: http_server_component.h:69
HttpServerComponent(HttpServerComponent const &)=delete
std::weak_ptr< HttpServer > srv_
Definition: http_server_component.h:72
HttpServerComponent()=default
std::vector< RouterData > request_handlers_
Definition: http_server_component.h:70
void operator=(HttpServerComponent const &)=delete
Definition: http_server_plugin.h:124
#define HTTP_SERVER_EXPORT
Definition: http_server_export.h:40
Definition: srv0dynamic_procedures.h:48
Definition: http_server_component.h:64
std::string url_regex_str
Definition: http_server_component.h:65
std::unique_ptr< BaseRequestHandler > handler
Definition: http_server_component.h:66