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 void CreateConnection(std::shared_ptr<netplus::con> &res);
70 std::string _altSvcH3; // Alt-Svc value for HTTP/3 advertisement
71
72 // TLS session cache — shared across all accepted SSL connections
73 // to enable abbreviated TLS 1.2 handshakes on client reconnection.
74 netplus::TlsSessionCache _tlsSessionCache;
75 private:
76 // Per-stream buffer for HTTP/3: accumulates data until fin
77 struct H3StreamBuffer {
78 std::vector<uint8_t> data;
79 };
80 std::mutex _h3BufferMutex;
81 std::map<uint64_t, H3StreamBuffer> _h3StreamBuffers;
82 std::atomic<int> _h3NextTid{0};
83 void _dispatchH2Stream(HttpRequest &cureq, std::string &out,
84 uint32_t sid,
85 const std::vector<hpack::HeaderField> &decoded,
86 const std::string &reqBody,
87 const int tid, ULONG_PTR args);
88 void _resumeH2Streams(HttpRequest &cureq, std::string &out,
89 const int tid, ULONG_PTR args);
90 void RequestEvent(netplus::con &curcon, const int tid, ULONG_PTR args);
91 void ResponseEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
92 void ConnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
93 void DisconnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
94
95 };
96
97 class HttpD {
98 public:
99 HttpD(int argc, char** argv);
100 HttpD(const std::string &httpaddr, int port, int maxconnections, const std::string &sslcertpath, const std::string &sslkeypath);
101 ~HttpD();
102 std::vector<netplus::socket*> getServerSockets();
103 protected:
104 void FileServer();
105 private:
106
107 bool _fileServer;
108 std::vector<std::unique_ptr<netplus::socket>> _ServerSockets;
109 std::map<std::string, netplus::ssl::CertificateBundle> _certBundle;
110 HTTPException _httpexception;
111 };
112};
Definition exception.h:42
Definition httpd.h:97
Definition httpd.h:49
Definition http.h:309