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 <cstdint>
31#include <map>
32#include <memory>
33#include <mutex>
34#include <string>
35#include <vector>
36
37#include "http.h"
38#include "exception.h"
39
40#pragma once
41
42namespace cmdplus {
43 class CmdController;
44}
45
46namespace libhttppp {
47 class HttpEvent : public netplus::event {
48 public:
49 HttpEvent(std::vector<netplus::socket*> serversocket,int timeout = 1000);
50
51 virtual void RequestEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
52 virtual void ResponseEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
53 virtual void ConnectEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
54 virtual void DisconnectEvent(HttpRequest &curreq,const int tid,ULONG_PTR args);
55
56 virtual bool Http2RequestEvent(netplus::con &curcon,
57 const int tid,
58 ULONG_PTR args,
59 const std::string &alpn,
60 const netplus::ssl::FramingCallback &frame_cb);
61 virtual void Http3StreamEvent(netplus::socket *sock,
62 uint64_t stream_id,
63 const std::vector<uint8_t> &data,
64 bool fin);
65
66 protected:
67 void CreateConnection(std::shared_ptr<netplus::con> &res);
68 std::string _altSvcH3; // Alt-Svc value for HTTP/3 advertisement
69 private:
70 // Per-stream buffer for HTTP/3: accumulates data until fin
71 struct H3StreamBuffer {
72 std::vector<uint8_t> data;
73 };
74 std::mutex _h3BufferMutex;
75 std::map<uint64_t, H3StreamBuffer> _h3StreamBuffers;
76 void _dispatchH2Stream(HttpRequest &cureq, std::string &out,
77 uint32_t sid,
78 const std::vector<hpack::HeaderField> &decoded,
79 const std::string &reqBody,
80 const int tid, ULONG_PTR args);
81 void RequestEvent(netplus::con &curcon, const int tid, ULONG_PTR args);
82 void ResponseEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
83 void ConnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
84 void DisconnectEvent(netplus::con &curcon,const int tid,ULONG_PTR args);
85
86 };
87
88 class HttpD {
89 public:
90 HttpD(int argc, char** argv);
91 HttpD(const std::string &httpaddr, int port, int maxconnections, const std::string &sslcertpath, const std::string &sslkeypath);
92 ~HttpD();
93 std::vector<netplus::socket*> getServerSockets();
94 protected:
95 void FileServer();
96 private:
97
98 bool _fileServer;
99 std::vector<std::unique_ptr<netplus::socket>> _ServerSockets;
100 std::map<std::string, netplus::ssl::CertificateBundle> _certBundle;
101 HTTPException _httpexception;
102 };
103};
Definition exception.h:42
Definition httpd.h:88
Definition httpd.h:47
Definition http.h:231