forked from fhessel/esp32_https_server
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHTTPSServer.hpp
More file actions
85 lines (69 loc) · 1.99 KB
/
HTTPSServer.hpp
File metadata and controls
85 lines (69 loc) · 1.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
/*
* HTTPSServer.hpp
*
* Created on: Dec 6, 2017
* Author: frank
*/
#ifndef HTTPS_HTTPSSERVER_HPP_
#define HTTPS_HTTPSSERVER_HPP_
// Standard library
#include <string>
// Arduino stuff
#include <Arduino.h>
// Required for SSL
#include "openssl/ssl.h"
#undef read
// Required for sockets
#include "lwip/netdb.h"
#undef read
#include "lwip/sockets.h"
#include "lwip/inet.h"
// Internal includes
#include "HTTPSServerConstants.hpp"
#include "HTTPHeaders.hpp"
#include "HTTPHeader.hpp"
#include "ResourceNode.hpp"
#include "ResourceResolver.hpp"
#include "ResolvedResource.hpp"
#include "HTTPSConnection.hpp"
#include "SSLCert.hpp"
namespace httpsserver {
class HTTPSServer : public ResourceResolver {
public:
HTTPSServer(SSLCert * cert, const uint16_t port = 443, const uint8_t maxConnections = 4, const in_addr_t bindAddress = 0);
virtual ~HTTPSServer();
uint8_t start();
void stop();
bool isRunning();
void loop();
void setDefaultHeader(std::string name, std::string value);
private:
// Static configuration. Port, keys, etc. ====================
// Certificate that should be used (includes private key)
SSLCert * _cert;
// Port that the server will listen on
const uint16_t _port;
// Max parallel connections that the server will accept
const uint8_t _maxConnections;
// Address to bind to (0 = all interfaces)
const in_addr_t _bindAddress;
//// Runtime data ============================================
// The array of connections that are currently active
HTTPSConnection ** _connections;
// The SSL context based on the cert and private key
SSL_CTX * _sslctx;
// Status of the server: Are we running, or not?
boolean _running;
// The server socket
int _socket;
// The server socket address, that our service is bound to
sockaddr_in _sock_addr;
// Headers that are included in every response
HTTPHeaders _defaultHeaders;
// Setup functions
uint8_t setupSSLCTX();
uint8_t setupCert();
uint8_t setupSocket();
};
} /* namespace httpsserver */
#endif /* HTTPS_HTTPSSERVER_HPP_ */