Skip to content

Commit 9077c16

Browse files
authored
grout host header & dynamic routing doc (#1490)
* `grout` host header & dynamic routing doc * spell fix * Link to repo
1 parent 79546ff commit 9077c16

File tree

1 file changed

+51
-0
lines changed

1 file changed

+51
-0
lines changed

README.md

+51
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@
7878
- [Grout Authentication](#grout-authentication)
7979
- [Grout Paths](#grout-paths)
8080
- [Grout Wildcard Domains](#grout-wildcard-domains)
81+
- ["Host" Header Based Wildcard Routing](#grout-wildcard-domain-routing-based-upon-host-header)
82+
- ["Dynamic" Routing](#grout-client-plugin)
8183
- [Grout using Docker](#grout-using-docker)
8284
- [How Grout works](#how-grout-works)
8385
- [Self-hosted Grout](#self-hosted-grout)
@@ -1443,6 +1445,55 @@ grout https://localhost:8080 custom.example.com --wildcard
14431445
2024-08-05 18:25:03,159 - setup - Grouting https://*.custom.domain.com
14441446
```
14451447

1448+
## Grout Wildcard Domain Routing Based Upon "Host" Header
1449+
1450+
> Only available with `--wildcard`
1451+
1452+
Along with the default route you can also provide additional routes which takes precedence when the host field matches. Example:
1453+
1454+
```console
1455+
grout https://localhost:8080 custom.example.com \
1456+
--wildcard \
1457+
--tunnel-route-url stream.example.com=http://localhost:7001
1458+
```
1459+
1460+
You can provide multiple custom routes by repeating this flag.
1461+
1462+
## Grout Client Plugin
1463+
1464+
`GroutClientBasePlugin` allows you to dynamically route traffic to different upstreams. Below is a simple implementation with some description about how to use it.
1465+
1466+
```python
1467+
class GroutClientPlugin(GroutClientBasePlugin):
1468+
1469+
def resolve_route(
1470+
self,
1471+
route: str,
1472+
request: HttpParser,
1473+
origin: HostPort,
1474+
server: HostPort,
1475+
) -> Tuple[Optional[str], HttpParser]:
1476+
print(request, origin, server, '->', route)
1477+
print(request.header(b'host'), request.path)
1478+
#
1479+
# Here, we send traffic to localhost:7001 irrespective
1480+
# of the original "route" value provided to the grout
1481+
# client OR any custom host:upstream mapping provided
1482+
# through the --tunnel-route-url flags (when using
1483+
# --wildcard).
1484+
#
1485+
# Optionally, you can also strip path before
1486+
# sending traffic to upstrem, like:
1487+
# request.path = b"/"
1488+
#
1489+
# To drop the request, simply return None for route
1490+
# return None, request
1491+
#
1492+
return 'http://localhost:7001', request
1493+
```
1494+
1495+
See [grout_client.py](https://github.com/abhinavsingh/proxy.py/blob/develop/proxy/plugin/grout_client.py) for more information. To try this out, start by passing `--plugin proxy.plugin.grout_client.GroutClientPlugin` when starting the grout client.
1496+
14461497
## Grout using Docker
14471498

14481499
```console

0 commit comments

Comments
 (0)