1
0
mirror of https://github.com/esp8266/Arduino.git synced 2025-06-16 11:21:18 +03:00

adding extra finctionaity the the web server

void onNotFound(bool(void)) handler routes and errors not in the
defined handlers
int args() returns nubmer of currentarguments
String arg(int i) returns the "i" argument value
String argName(int i) returns the "i" argument name(key)
bool hasArg(const char * name) looks up if an argument exist by
seraching for it's key
This commit is contained in:
ficeto
2015-05-01 02:43:51 +03:00
parent fbec557ddb
commit 81af3a061e
2 changed files with 42 additions and 7 deletions

View File

@ -39,22 +39,27 @@ public:
void handleClient();
typedef std::function<void(void)> THandlerFunction;
typedef std::function<bool(void)> TNotFoundHandlerFunction;
void on(const char* uri, THandlerFunction handler);
void on(const char* uri, HTTPMethod method, THandlerFunction fn);
void onNotFound(TNotFoundHandlerFunction fn);//called when handler is not assigned
String uri() { return _currentUri; }
HTTPMethod method() { return _currentMethod; }
WiFiClient client() { return _currentClient; }
String arg(const char* name);// get request argument value
String arg(int i);// get request argument value buy number
String argName(int i);// get request argument name buy number
int args();//get arguments count
bool hasArg(const char* name);//check if argument exists
// send response to the client
// code - HTTP response code, can be 200 or 404
// content_type - HTTP content type, like "text/plain" or "image/png"
// content - actual content body
void send(int code, const char* content_type = NULL, String content = String(""));
// get request argument value
String arg(const char* name);
protected:
void _handleRequest(WiFiClient& client, String uri, HTTPMethod method);
void _parseArguments(String data);
@ -76,6 +81,7 @@ protected:
RequestHandler* _firstHandler;
RequestHandler* _lastHandler;
TNotFoundHandlerFunction _notFoundHandler;
};