Skip to content
This repository was archived by the owner on Mar 5, 2026. It is now read-only.

Commit 6dcea3f

Browse files
rjlexxme-no-dev
authored andcommitted
Add handlers by URL templates (me-no-dev#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
1 parent 781bddf commit 6dcea3f

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

src/WebHandlerImpl.h

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,13 @@ class AsyncCallbackWebHandler: public AsyncWebHandler {
8383
if(!(_method & request->method()))
8484
return false;
8585

86-
if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/")))
86+
if (_uri.length() && _uri.endsWith("*")) {
87+
String uriTemplate = String(_uri);
88+
uriTemplate = uriTemplate.substring(0, uriTemplate.length() - 1);
89+
if (!request->url().startsWith(uriTemplate))
90+
return false;
91+
}
92+
else if(_uri.length() && (_uri != request->url() && !request->url().startsWith(_uri+"/")))
8793
return false;
8894

8995
request->addInterestingHeader("ANY");

0 commit comments

Comments
 (0)