ESP32 HTTPS Server

HTTPServer.hpp
1 #ifndef SRC_HTTPSERVER_HPP_
2 #define SRC_HTTPSERVER_HPP_
3
4 // Standard library
5 #include <string>
6
7 // Arduino stuff
8 #include <Arduino.h>
9
10 // Required for sockets
11 #include "lwip/netdb.h"
12 #undef read
13 #include "lwip/sockets.h"
14 #include "lwip/inet.h"
15
16 // Internal includes
17 #include "HTTPSServerConstants.hpp"
18 #include "HTTPHeaders.hpp"
19 #include "HTTPHeader.hpp"
20 #include "ResourceNode.hpp"
21 #include "ResourceResolver.hpp"
22 #include "ResolvedResource.hpp"
23 #include "HTTPConnection.hpp"
24
25 namespace httpsserver {
26
30 class HTTPServer : public ResourceResolver {
31 public:
32 HTTPServer(const uint16_t portHTTPS = 80, const uint8_t maxConnections = 8, const in_addr_t bindAddress = 0);
33 virtual ~HTTPServer();
34
35 uint8_t start();
36 void stop();
37 bool isRunning();
38
39 void loop();
40
41 void setDefaultHeader(std::string name, std::string value);
42
43 protected:
44 // Static configuration. Port, keys, etc. ====================
45 // Certificate that should be used (includes private key)
46 const uint16_t _port;
47
48 // Max parallel connections that the server will accept
49 const uint8_t _maxConnections;
50 // Address to bind to (0 = all interfaces)
51 const in_addr_t _bindAddress;
52
54 // The array of connections that are currently active
55 HTTPConnection ** _connections;
56 // Status of the server: Are we running, or not?
57 boolean _running;
58 // The server socket
59 int _socket;
60
61 // The server socket address, that our service is bound to
62 sockaddr_in _sock_addr;
63 // Headers that are included in every response
64 HTTPHeaders _defaultHeaders;
65
66 // Setup functions
67 virtual uint8_t setupSocket();
68 virtual void teardownSocket();
69
70 // Helper functions
71 virtual int createConnection(int idx);
72 };
73
74 }
75
76 #endif /* SRC_HTTPSERVER_HPP_ */
httpsserver::HTTPServer::loop
void loop()
Definition: HTTPServer.cpp:99
httpsserver::HTTPServer
Main implementation for the plain HTTP server. Use HTTPSServer for TLS support.
Definition: HTTPServer.hpp:30
httpsserver::HTTPHeaders
Groups and manages a set of HTTPHeader instances.
Definition: HTTPHeaders.hpp:18
httpsserver::HTTPServer::setupSocket
virtual uint8_t setupSocket()
Definition: HTTPServer.cpp:170
httpsserver::HTTPServer::setDefaultHeader
void setDefaultHeader(std::string name, std::string value)
Definition: HTTPServer.cpp:91
httpsserver::ResourceResolver
This class is used internally to resolve a string URL to the corresponding HTTPNode.
Definition: ResourceResolver.hpp:22
httpsserver::HTTPServer::stop
void stop()
Definition: HTTPServer.cpp:54
httpsserver::HTTPConnection
Represents a single open connection for the plain HTTPServer, without TLS.
Definition: HTTPConnection.hpp:37
httpsserver::HTTPServer::start
uint8_t start()
Definition: HTTPServer.cpp:35
httpsserver
Definition: ConnectionContext.cpp:3