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
22
#include <
sese/service/http/HttpService.h
>
23
#include <
sese/net/http/Controller.h
>
24
25
namespace
sese::service::http
{
26
29
class
HttpServer
final {
30
public
:
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
56
void
regTailFilter
(
const
HttpService::FilterCallback
&
tail_filter
);
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
73
void
setConnectionCallback
(
const
HttpService::ConnectionCallback
&
callback
);
74
77
bool
startup
()
const
;
78
81
bool
shutdown
()
const
;
82
83
private
:
84
std::string
name
;
85
uint32_t
keepalive
= 5;
86
std::vector<HttpService::Ptr>
services
;
87
std::vector<net::http::Controller::Ptr>
controllers
;
88
HttpService::MountPointMap
mount_points
;
89
HttpService::ServletMap
servlets
;
90
HttpService::FilterMap
filters
;
91
HttpService::FilterCallback
tail_filter
;
92
HttpService::ConnectionCallback
connection_callback
;
93
};
94
95
template
<
class
CTL,
class
... ARGS>
96
void
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
sese
service
http
HttpServer.h
Generated on Tue Jan 7 2025 15:49:06 for Sese Framework by
1.11.0