WebServer.h 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. #ifndef _WEBSERVER_H
  2. #define _WEBSERVER_H
  3. #include <Arduino.h>
  4. #include <ArduinoJson.h>
  5. #include <ESP8266WebServer.h>
  6. #include <PatternHandler.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, PatternHandler::TPatternHandlerFn fn);
  17. void onPatternAuthenticated(const String& pattern, const HTTPMethod method, PatternHandler::TPatternHandlerFn handler);
  18. bool matchesPattern(const String& pattern, const String& url);
  19. void requireAuthentication(const String& username, const String& password);
  20. void disableAuthentication();
  21. bool validateAuthentiation();
  22. inline bool clientConnected() {
  23. return _currentClient && _currentClient.connected();
  24. }
  25. bool authenticationRequired() {
  26. return authEnabled;
  27. }
  28. protected:
  29. bool authEnabled;
  30. String username;
  31. String password;
  32. };
  33. #endif