PsychichHTTP v2-dev
This commit is contained in:
@@ -6,23 +6,21 @@
|
||||
|
||||
class PsychicEndpoint;
|
||||
class PsychicHttpServer;
|
||||
class PsychicMiddleware;
|
||||
class PsychicMiddlewareChain;
|
||||
|
||||
/*
|
||||
* HANDLER :: Can be attached to any endpoint or as a generic request handler.
|
||||
*/
|
||||
* HANDLER :: Can be attached to any endpoint or as a generic request handler.
|
||||
*/
|
||||
|
||||
class PsychicHandler {
|
||||
friend PsychicEndpoint;
|
||||
class PsychicHandler
|
||||
{
|
||||
friend PsychicEndpoint;
|
||||
|
||||
protected:
|
||||
PsychicRequestFilterFunction _filter;
|
||||
PsychicHttpServer *_server;
|
||||
|
||||
String _username;
|
||||
String _password;
|
||||
HTTPAuthMethod _method;
|
||||
String _realm;
|
||||
String _authFailMsg;
|
||||
PsychicHttpServer* _server = nullptr;
|
||||
PsychicMiddlewareChain* _chain = nullptr;
|
||||
std::list<PsychicRequestFilterFunction> _filters;
|
||||
|
||||
String _subprotocol;
|
||||
|
||||
@@ -32,35 +30,39 @@ class PsychicHandler {
|
||||
PsychicHandler();
|
||||
virtual ~PsychicHandler();
|
||||
|
||||
PsychicHandler* setFilter(PsychicRequestFilterFunction fn);
|
||||
bool filter(PsychicRequest *request);
|
||||
|
||||
PsychicHandler* setAuthentication(const char *username, const char *password, HTTPAuthMethod method = BASIC_AUTH, const char *realm = "", const char *authFailMsg = "");
|
||||
bool needsAuthentication(PsychicRequest *request);
|
||||
esp_err_t authenticate(PsychicRequest *request);
|
||||
|
||||
virtual bool isWebSocket() { return false; };
|
||||
|
||||
void setSubprotocol(const String& subprotocol);
|
||||
const char* getSubprotocol() const;
|
||||
|
||||
PsychicClient * checkForNewClient(PsychicClient *client);
|
||||
void checkForClosedClient(PsychicClient *client);
|
||||
PsychicClient* checkForNewClient(PsychicClient* client);
|
||||
void checkForClosedClient(PsychicClient* client);
|
||||
|
||||
virtual void addClient(PsychicClient *client);
|
||||
virtual void removeClient(PsychicClient *client);
|
||||
virtual PsychicClient * getClient(int socket);
|
||||
virtual PsychicClient * getClient(PsychicClient *client);
|
||||
virtual void openCallback(PsychicClient *client) {};
|
||||
virtual void closeCallback(PsychicClient *client) {};
|
||||
virtual void addClient(PsychicClient* client);
|
||||
virtual void removeClient(PsychicClient* client);
|
||||
virtual PsychicClient* getClient(int socket);
|
||||
virtual PsychicClient* getClient(PsychicClient* client);
|
||||
virtual void openCallback(PsychicClient* client) {};
|
||||
virtual void closeCallback(PsychicClient* client) {};
|
||||
|
||||
bool hasClient(PsychicClient *client);
|
||||
bool hasClient(PsychicClient* client);
|
||||
int count() { return _clients.size(); };
|
||||
const std::list<PsychicClient*>& getClientList();
|
||||
|
||||
//derived classes must implement these functions
|
||||
virtual bool canHandle(PsychicRequest *request) { return true; };
|
||||
virtual esp_err_t handleRequest(PsychicRequest *request) = 0;
|
||||
// called to process this handler with its middleware chain and filers
|
||||
esp_err_t process(PsychicRequest* request);
|
||||
|
||||
//bool filter(PsychicRequest* request);
|
||||
PsychicHandler* addFilter(PsychicRequestFilterFunction fn);
|
||||
bool filter(PsychicRequest* request);
|
||||
|
||||
PsychicHandler* addMiddleware(PsychicMiddleware* middleware);
|
||||
PsychicHandler* addMiddleware(PsychicMiddlewareCallback fn);
|
||||
void removeMiddleware(PsychicMiddleware *middleware);
|
||||
|
||||
// derived classes must implement these functions
|
||||
virtual bool canHandle(PsychicRequest* request) { return true; };
|
||||
virtual esp_err_t handleRequest(PsychicRequest* request, PsychicResponse* response) { return HTTPD_404_NOT_FOUND; };
|
||||
};
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user