From 6dcea3f5e724a84b784f44bee23508d3895a9ad5 Mon Sep 17 00:00:00 2001 From: rjlexx <34487573+rjlexx@users.noreply.github.com> Date: Sat, 22 Jun 2019 19:28:24 +0300 Subject: [PATCH] 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 --- src/WebHandlerImpl.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/WebHandlerImpl.h b/src/WebHandlerImpl.h index b2da6fe..65b580f 100644 --- a/src/WebHandlerImpl.h +++ b/src/WebHandlerImpl.h @@ -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");