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:
parent
781bddf20c
commit
6dcea3f5e7
|
@ -83,7 +83,13 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
|
||||||
if(!(_method & request->method()))
|
if(!(_method & request->method()))
|
||||||
return false;
|
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;
|
return false;
|
||||||
|
|
||||||
request->addInterestingHeader("ANY");
|
request->addInterestingHeader("ANY");
|
||||||
|
|
Loading…
Reference in New Issue