WebServer.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #ifndef _WEBSERVER_H
  2. #define _WEBSERVER_H
  3. #include <Arduino.h>
  4. #include <ArduinoJson.h>
  5. #include <ESP8266WebServer.h>
  6. #include <PathVariableHandler.h>
  7. #define HTTP_DOWNLOAD_UNIT_SIZE 1460
  8. #define HTTP_MAX_SEND_WAIT 5000 //ms to wait for data chunk to be ACKed
  9. #define HTTP_MAX_CLOSE_WAIT 2000 //ms to wait for the client to close the connection
  10. class WebServer : public ESP8266WebServer {
  11. public:
  12. WebServer(int port) : ESP8266WebServer(port) { }
  13. void onAuthenticated(const String &uri, THandlerFunction handler);
  14. void onAuthenticated(const String &uri, HTTPMethod method, THandlerFunction fn);
  15. void onAuthenticated(const String &uri, HTTPMethod method, THandlerFunction fn, THandlerFunction ufn);
  16. void onPattern(const String& pattern, const HTTPMethod method, PathVariableHandler::TPathVariableHandlerFn fn);
  17. void onPatternAuthenticated(const String& pattern, const HTTPMethod method, PathVariableHandler::TPathVariableHandlerFn handler);
  18. void requireAuthentication(const String& username, const String& password);
  19. void disableAuthentication();
  20. bool validateAuthentiation();
  21. inline bool clientConnected() {
  22. return _currentClient && _currentClient.connected();
  23. }
  24. bool authenticationRequired() {
  25. return authEnabled;
  26. }
  27. protected:
  28. bool authEnabled;
  29. String username;
  30. String password;
  31. };
  32. #endif