Sese Framework  2.3.0
A cross-platform framework
Loading...
Searching...
No Matches
HttpServer.h
Go to the documentation of this file.
1// Copyright 2024 libsese
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
19
20#pragma once
21
24
26
29class HttpServer final {
30public:
35 template<class CTL, class... ARGS>
36 void regController(ARGS &&...args);
37
41 void regMountPoint(const std::string &uri_prefix, const std::string &local);
42
46 void regFilter(const std::string &uri_prefix, const HttpService::FilterCallback &callback);
47
50 void regServlet(const net::http::Servlet &servlet);
51
57
60 void setKeepalive(uint32_t seconds);
61
65 void regService(const net::IPAddress::Ptr &address, std::unique_ptr<security::SSLContext> context);
66
69 void setName(const std::string &name);
70
74
77 bool startup() const;
78
81 bool shutdown() const;
82
83private:
84 std::string name;
85 uint32_t keepalive = 5;
86 std::vector<HttpService::Ptr> services;
87 std::vector<net::http::Controller::Ptr> controllers;
93};
94
95template<class CTL, class... ARGS>
96void HttpServer::regController(ARGS &&...args) {
97 auto controller = std::make_shared<CTL>(std::forward<ARGS>(args)...);
98 controller->init();
99 for (auto &&servlet: *controller) {
100 servlets.emplace(servlet.getUri(), servlet);
101 }
102 controllers.push_back(controller); // GCOVR_EXCL_LINE
103}
104
105} // namespace sese::service::http::v3