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

Commit 2dc705c

Browse files
authored
Update README.md
1 parent 9a5be71 commit 2dc705c

1 file changed

Lines changed: 53 additions & 1 deletion

File tree

README.md

Lines changed: 53 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ For ESP32 it requires [AsyncTCP](https://github.com/me-no-dev/AsyncTCP) to work
1111
To use this library you might need to have the latest git versions of [ESP32](https://github.com/espressif/arduino-esp32) Arduino Core
1212

1313
## Table of contents
14-
- [ESPAsyncWebServer ![Build Status](https://travis-ci.org/me-no-dev/ESPAsyncWebServer)](#espasyncwebserver-build-statushttpstravis-ciorgme-no-devespasyncwebserver)
14+
- [ESPAsyncWebServer](#espasyncwebserver)
1515
- [Table of contents](#table-of-contents)
1616
- [Installation](#installation)
1717
- [Using PlatformIO](#using-platformio)
@@ -66,6 +66,7 @@ To use this library you might need to have the latest git versions of [ESP32](ht
6666
- [Specifying Cache-Control header](#specifying-cache-control-header)
6767
- [Specifying Date-Modified header](#specifying-date-modified-header)
6868
- [Specifying Template Processor callback](#specifying-template-processor-callback)
69+
- [Param Rewrite With Matching](#param-rewrite-with-matching)
6970
- [Using filters](#using-filters)
7071
- [Serve different site files in AP mode](#serve-different-site-files-in-ap-mode)
7172
- [Rewrite to different index on AP](#rewrite-to-different-index-on-ap)
@@ -853,6 +854,57 @@ String processor(const String& var)
853854
server.serveStatic("/", SPIFFS, "/www/").setTemplateProcessor(processor);
854855
```
855856
857+
## Param Rewrite With Matching
858+
It is possible to rewrite the request url with parameter matchg. Here is an example with one parameter:
859+
Rewrite for example "/radio/{frequence}" -> "/radio?f={frequence}"
860+
861+
```cpp
862+
class OneParamRewrite : public AsyncWebRewrite
863+
{
864+
protected:
865+
String _urlPrefix;
866+
int _paramIndex;
867+
String _paramsBackup;
868+
869+
public:
870+
OneParamRewrite(const char* from, const char* to)
871+
: AsyncWebRewrite(from, to) {
872+
873+
_paramIndex = _from.indexOf('{');
874+
875+
if( _paramIndex >=0 && _from.endsWith("}")) {
876+
_urlPrefix = _from.substring(0, _paramIndex);
877+
int index = _params.indexOf('{');
878+
if(index >= 0) {
879+
_params = _params.substring(0, index);
880+
}
881+
} else {
882+
_urlPrefix = _from;
883+
}
884+
_paramsBackup = _params;
885+
}
886+
887+
bool match(AsyncWebServerRequest *request) override {
888+
if(request->url().startsWith(_urlPrefix)) {
889+
if(_paramIndex >= 0) {
890+
_params = _paramsBackup + request->url().substring(_paramIndex);
891+
} else {
892+
_params = _paramsBackup;
893+
}
894+
return true;
895+
896+
} else {
897+
return false;
898+
}
899+
}
900+
};
901+
```
902+
903+
Usage:
904+
905+
```cpp
906+
server.addRewrite( new OneParamRewrite("/radio/{frequence}", "/radio?f={frequence}") );
907+
```
856908

857909
## Using filters
858910
Filters can be set to `Rewrite` or `Handler` in order to control when to apply the rewrite and consider the handler.

0 commit comments

Comments
 (0)