Add handlers by URL templates (#380)

* Add handlers by URL templates

This change allows add handlers by URL templates. 
For example:
server.on("/gpio*", handleGpio);
server.on("/irsend*", handleIrsend);
The "handleGpio" handler will handle all requests starting with "/gpio" and manage all GPIOs.
The "handleGpio" handler will handle all requests starting with "/irsend" and forward commands to IR manager.

* String::replace method changed to String::substring() method
This commit is contained in:
rjlexx 2019-06-22 19:28:24 +03:00 committed by Me No Dev
parent 781bddf20c
commit 6dcea3f5e7
1 changed files with 7 additions and 1 deletions

View File

@ -83,7 +83,13 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
if(!(_method & request->method()))
return false;
if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/")))
if (_uri.length() && _uri.endsWith("*")) {
String uriTemplate = String(_uri);
uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1);
if (!request->url().startsWith(uriTemplate))
return false;
}
else if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/")))
return false;
request->addInterestingHeader("ANY");