mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-02 20:24:40 +02:00
Fix #151: setAuthentication() was not authenticating: the middleware was setup with AUTH_NONE
(default) instead of AUTH_DIGEST
(to keep backward compatibility)
This commit is contained in:
@@ -412,6 +412,9 @@ void setup() {
|
|||||||
// curl -v -X GET http://192.168.4.1/index.txt
|
// curl -v -X GET http://192.168.4.1/index.txt
|
||||||
server.serveStatic("/index.txt", LittleFS, "/index.txt");
|
server.serveStatic("/index.txt", LittleFS, "/index.txt");
|
||||||
|
|
||||||
|
// curl -v -X GET http://192.168.4.1/index-private.txt
|
||||||
|
server.serveStatic("/index-private.txt", LittleFS, "/index.txt").setAuthentication("admin", "admin");
|
||||||
|
|
||||||
// ServeStatic static is used to serve static output which never changes over time.
|
// ServeStatic static is used to serve static output which never changes over time.
|
||||||
// This special endpoints automatyically adds caching headers.
|
// This special endpoints automatyically adds caching headers.
|
||||||
// If a template processor is used, it must enure that the outputed content will always be the ame over time and never changes.
|
// If a template processor is used, it must enure that the outputed content will always be the ame over time and never changes.
|
||||||
|
@@ -733,8 +733,8 @@ class AsyncWebHandler : public AsyncMiddlewareChain {
|
|||||||
AsyncWebHandler() {}
|
AsyncWebHandler() {}
|
||||||
virtual ~AsyncWebHandler() {}
|
virtual ~AsyncWebHandler() {}
|
||||||
AsyncWebHandler& setFilter(ArRequestFilterFunction fn);
|
AsyncWebHandler& setFilter(ArRequestFilterFunction fn);
|
||||||
AsyncWebHandler& setAuthentication(const char* username, const char* password);
|
AsyncWebHandler& setAuthentication(const char* username, const char* password, AsyncAuthType authMethod = AsyncAuthType::AUTH_DIGEST);
|
||||||
AsyncWebHandler& setAuthentication(const String& username, const String& password) { return setAuthentication(username.c_str(), password.c_str()); };
|
AsyncWebHandler& setAuthentication(const String& username, const String& password, AsyncAuthType authMethod = AsyncAuthType::AUTH_DIGEST) { return setAuthentication(username.c_str(), password.c_str(), authMethod); };
|
||||||
bool filter(AsyncWebServerRequest* request) { return _filter == NULL || _filter(request); }
|
bool filter(AsyncWebServerRequest* request) { return _filter == NULL || _filter(request); }
|
||||||
virtual bool canHandle(AsyncWebServerRequest* request __attribute__((unused))) const { return false; }
|
virtual bool canHandle(AsyncWebServerRequest* request __attribute__((unused))) const { return false; }
|
||||||
virtual void handleRequest(__unused AsyncWebServerRequest* request) {}
|
virtual void handleRequest(__unused AsyncWebServerRequest* request) {}
|
||||||
|
@@ -27,7 +27,7 @@ AsyncWebHandler& AsyncWebHandler::setFilter(ArRequestFilterFunction fn) {
|
|||||||
_filter = fn;
|
_filter = fn;
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
AsyncWebHandler& AsyncWebHandler::setAuthentication(const char* username, const char* password) {
|
AsyncWebHandler& AsyncWebHandler::setAuthentication(const char* username, const char* password, AsyncAuthType authMethod) {
|
||||||
if (!_authMiddleware) {
|
if (!_authMiddleware) {
|
||||||
_authMiddleware = new AuthenticationMiddleware();
|
_authMiddleware = new AuthenticationMiddleware();
|
||||||
_authMiddleware->_freeOnRemoval = true;
|
_authMiddleware->_freeOnRemoval = true;
|
||||||
@@ -35,6 +35,7 @@ AsyncWebHandler& AsyncWebHandler::setAuthentication(const char* username, const
|
|||||||
}
|
}
|
||||||
_authMiddleware->setUsername(username);
|
_authMiddleware->setUsername(username);
|
||||||
_authMiddleware->setPassword(password);
|
_authMiddleware->setPassword(password);
|
||||||
|
_authMiddleware->setAuthType(authMethod);
|
||||||
return *this;
|
return *this;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user