@@ -48,7 +48,7 @@ enum HTTPAuthMethod { BASIC_AUTH, DIGEST_AUTH };
48
48
#define CONTENT_LENGTH_UNKNOWN ((size_t ) -1 )
49
49
#define CONTENT_LENGTH_NOT_SET ((size_t ) -2 )
50
50
51
- class ESP8266WebServer ;
51
+ template < class ServerClass , class ClientClass > class ESP8266WebServerTemplate ;
52
52
53
53
typedef struct {
54
54
HTTPUploadStatus status;
@@ -66,18 +66,19 @@ namespace fs {
66
66
class FS ;
67
67
}
68
68
69
- class ESP8266WebServer
69
+ template <class ServerClass , class ClientClass >
70
+ class ESP8266WebServerTemplate
70
71
{
71
72
public:
72
- ESP8266WebServer (IPAddress addr, int port = 80 );
73
- ESP8266WebServer (int port = 80 );
74
- virtual ~ESP8266WebServer ();
73
+ ESP8266WebServerTemplate (IPAddress addr, int port = 80 );
74
+ ESP8266WebServerTemplate (int port = 80 );
75
+ ~ESP8266WebServerTemplate ();
75
76
76
- virtual void begin ();
77
- virtual void begin (uint16_t port);
78
- virtual void handleClient ();
77
+ void begin ();
78
+ void begin (uint16_t port);
79
+ void handleClient ();
79
80
80
- virtual void close ();
81
+ void close ();
81
82
void stop ();
82
83
83
84
bool authenticate (const char * username, const char * password);
@@ -87,14 +88,14 @@ class ESP8266WebServer
87
88
void on (const String &uri, THandlerFunction handler);
88
89
void on (const String &uri, HTTPMethod method, THandlerFunction fn);
89
90
void on (const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
90
- void addHandler (RequestHandler* handler);
91
+ void addHandler (RequestHandler<ServerClass, ClientClass> * handler);
91
92
void serveStatic (const char * uri, fs::FS& fs, const char * path, const char * cache_header = NULL );
92
93
void onNotFound (THandlerFunction fn); // called when handler is not assigned
93
94
void onFileUpload (THandlerFunction fn); // handle file uploads
94
95
95
96
String uri () { return _currentUri; }
96
97
HTTPMethod method () { return _currentMethod; }
97
- virtual WiFiClient client () { return _currentClient; }
98
+ ClientClass client () { return _currentClient; }
98
99
HTTPUpload& upload () { return *_currentUpload; }
99
100
100
101
String arg (String name); // get request argument value by name
@@ -134,20 +135,26 @@ class ESP8266WebServer
134
135
_streamFileCore (file.size (), file.name (), contentType);
135
136
return _currentClient.write (file);
136
137
}
137
-
138
+
139
+ // AXTLS and BearSSL only
140
+ void setServerKeyAndCert (const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) { }
141
+ void setServerKeyAndCert_P (const uint8_t *key, int keyLen, const uint8_t *cert, int certLen) { }
142
+ // BearSSL only
143
+ void setBufferSizes (int recv, int xmit) { };
144
+ void setRSACert (const BearSSLX509List *chain, const BearSSLPrivateKey *sk) { };
145
+ void setECCert (const BearSSLX509List *chain, unsigned cert_issuer_key_type, const BearSSLPrivateKey *sk) { };
146
+
138
147
protected:
139
- virtual size_t _currentClientWrite (const char * b, size_t l) { return _currentClient.write ( b, l ); }
140
- virtual size_t _currentClientWrite_P (PGM_P b, size_t l) { return _currentClient.write_P ( b, l ); }
141
- void _addRequestHandler (RequestHandler* handler);
148
+ void _addRequestHandler (RequestHandler<ServerClass, ClientClass>* handler);
142
149
void _handleRequest ();
143
150
void _finalizeResponse ();
144
- bool _parseRequest (WiFiClient & client);
151
+ bool _parseRequest (ClientClass & client);
145
152
void _parseArguments (String data);
146
153
static String _responseCodeToString (int code);
147
- bool _parseForm (WiFiClient & client, String boundary, uint32_t len);
154
+ bool _parseForm (ClientClass & client, String boundary, uint32_t len);
148
155
bool _parseFormUploadAborted ();
149
156
void _uploadWriteByte (uint8_t b);
150
- uint8_t _uploadReadByte (WiFiClient & client);
157
+ uint8_t _uploadReadByte (ClientClass & client);
151
158
void _prepareHeader (String& response, int code, const char * content_type, size_t contentLength);
152
159
bool _collectHeader (const char * headerName, const char * headerValue);
153
160
@@ -162,18 +169,18 @@ class ESP8266WebServer
162
169
String value;
163
170
};
164
171
165
- WiFiServer _server;
172
+ ServerClass _server;
166
173
167
- WiFiClient _currentClient;
174
+ ClientClass _currentClient;
168
175
HTTPMethod _currentMethod;
169
176
String _currentUri;
170
177
uint8_t _currentVersion;
171
178
HTTPClientStatus _currentStatus;
172
179
unsigned long _statusChange;
173
180
174
- RequestHandler* _currentHandler;
175
- RequestHandler* _firstHandler;
176
- RequestHandler* _lastHandler;
181
+ RequestHandler<ServerClass, ClientClass> * _currentHandler;
182
+ RequestHandler<ServerClass, ClientClass> * _firstHandler;
183
+ RequestHandler<ServerClass, ClientClass> * _lastHandler;
177
184
THandlerFunction _notFoundHandler;
178
185
THandlerFunction _fileUploadHandler;
179
186
@@ -195,5 +202,9 @@ class ESP8266WebServer
195
202
196
203
};
197
204
205
+ #include " ESP8266WebServer-impl.h"
206
+ #include " Parsing-impl.h"
207
+
208
+ typedef ESP8266WebServerTemplate<WiFiServer, WiFiClient> ESP8266WebServer;
198
209
199
210
#endif // ESP8266WEBSERVER_H
0 commit comments