WebServer.h 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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_UPLOAD_BUFLEN 2048
  9. #define HTTP_MAX_DATA_WAIT 1000 //ms to wait for the client to send the request
  10. #define HTTP_MAX_POST_WAIT 1000 //ms to wait for POST data to arrive
  11. #define HTTP_MAX_SEND_WAIT 5000 //ms to wait for data chunk to be ACKed
  12. #define HTTP_MAX_CLOSE_WAIT 2000 //ms to wait for the client to close the connection
  13. class WebServer : public ESP8266WebServer {
  14. public:
  15. WebServer(int port) : ESP8266WebServer(port) { }
  16. bool matchesPattern(const String& pattern, const String& url);
  17. void onPattern(const String& pattern, const HTTPMethod method, PatternHandler::TPatternHandlerFn fn);
  18. void requireAuthentication(const String& username, const String& password);
  19. void disableAuthentication();
  20. inline bool clientConnected() {
  21. return _currentClient && _currentClient.connected();
  22. }
  23. // These are copied / patched from ESP8266WebServer because they aren't
  24. // virtual. (*barf*)
  25. void handleClient();
  26. void _handleRequest();
  27. bool authenticationRequired() {
  28. return authEnabled;
  29. }
  30. protected:
  31. bool authEnabled;
  32. String username;
  33. String password;
  34. void resetPathMatches();
  35. void checkPatterns();
  36. };
  37. #endif