Sese Framework  x.y.z
A cross-platform framework
载入中...
搜索中...
未找到
HttpServiceImpl.h
浏览该文件的文档.
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
15#pragma once
16
17#include <optional>
19
22
24
27 public std::enable_shared_from_this<HttpServiceImpl> {
28public:
29 friend struct HttpConnection;
30 friend struct HttpConnectionEx;
31
35 uint32_t keepalive,
36 std::string &serv_name,
42 );
43
44 bool startup() override;
45
46 bool shutdown() override;
47
48 int getLastError() override;
49
50 std::string getLastErrorMessage() override;
51
52 uint32_t getKeepalive() const { return keepalive; }
53
54 void handleFilter(const Handleable::Ptr &conn) const;
55
56 void handleRequest(const Handleable::Ptr &conn) const;
57
58private:
59 asio::io_context io_context;
60 std::optional<asio::ssl::context> ssl_context;
61 asio::ip::tcp::acceptor acceptor;
62 asio::error_code error;
63
64 static constexpr unsigned char ALPN_PROTOS[] = "\x2h2\x8http/1.1";
65
66 static int alpnCallback(SSL *ssl, const uint8_t **out, uint8_t *out_length, const uint8_t *in, uint32_t in_length, void *data);
67
68 void handleAccept();
69
70 void handleSSLAccept();
71
72 std::set<HttpConnection::Ptr> connections;
73 std::set<HttpConnectionEx::Ptr> connections2;
74};
75
76}