libhttppp ..
Loading...
Searching...
No Matches
httpd.h
1/*******************************************************************************
2 * Copyright (c) 2014, Jan Koester jan.koester@gmx.net
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
7 * Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * Neither the name of the <organization> nor the
13 * names of its contributors may be used to endorse or promote products
14 * derived from this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
19 * DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
20 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
21 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
22 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
23 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
25 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26 *******************************************************************************/
27
28#include <netplus/socket.h>
29#include <netplus/eventapi.h>
30#include <atomic>
31#include <cstdint>
32#include <map>
33#include <memory>
34#include <mutex>
35#include <set>
36#include <string>
37#include <vector>
38
39#include "http.h"
40#include "exception.h"
41
42#pragma once
43
44namespace cmdplus {
45 class CmdController;
46}
47
48namespace libhttppp {
49 class HttpEvent : public netplus::event {
50 public:
51 HttpEvent(std::vector<netplus::socket*> serversocket,int timeout = 1000);
52
53 virtual void RequestEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
54 virtual void ResponseEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
55 virtual void ConnectEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
56 virtual void DisconnectEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
57
58 virtual bool Http2RequestEvent(netplus::con &curcon,
59 const int tid,
60 ULONG_PTR args,
61 const std::string &alpn,
62 const netplus::ssl::FramingCallback &frame_cb);
63 virtual void Http3StreamEvent(netplus::socket *sock,
64 uint64_t stream_id,
65 const std::vector<uint8_t> &data,
66 bool fin);
67
68 protected:
69 virtual void CreateConnection(std::shared_ptr<netplus::con> &res);
70
71 virtual void RequestEvent(netplus::con &curcon, const int tid, ULONG_PTR args);
72 virtual void ResponseEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
73 virtual void ConnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
74 virtual void DisconnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
75
76 std::string _altSvcH3; // Alt-Svc value for HTTP/3 advertisement
77
78 // TLS session cache — shared across all accepted SSL connections
79 // to enable abbreviated TLS 1.2 handshakes on client reconnection.
80 netplus::TlsSessionCache _tlsSessionCache;
81 private:
82 // Per-stream buffer for HTTP/3: accumulates data until fin
83 struct H3StreamBuffer {
84 std::vector<uint8_t> data;
85 };
86 std::mutex _h3BufferMutex;
87 std::map<uint64_t, H3StreamBuffer> _h3StreamBuffers;
88 std::atomic<int> _h3NextTid{0};
89 void _dispatchH2Stream(HttpRequest &cureq, std::string &out,
90 uint32_t sid,
91 const std::vector<hpack::HeaderField> &decoded,
92 const std::string &reqBody,
93 const int tid, ULONG_PTR args);
94 void _resumeH2Streams(HttpRequest &cureq, std::string &out,
95 const int tid, ULONG_PTR args);
96 };
97
98 class HttpD {
99 public:
100 HttpD(int argc, char** argv);
101 HttpD(const std::string &httpaddr, int port, int maxconnections, const std::string &sslcertpath, const std::string &sslkeypath);
102 ~HttpD();
103 std::vector<netplus::socket*> getServerSockets();
104 protected:
105 void FileServer();
106 private:
107
108 bool _fileServer;
109 std::vector<std::unique_ptr<netplus::socket>> _ServerSockets;
110 std::map<std::string, netplus::ssl::CertificateBundle> _certBundle;
111 HTTPException _httpexception;
112 };
113};
Definition exception.h:42
Definition httpd.h:98
Definition httpd.h:49
Definition http.h:309