|
78 | 78 | - [Grout Authentication](#grout-authentication)
|
79 | 79 | - [Grout Paths](#grout-paths)
|
80 | 80 | - [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) |
81 | 83 | - [Grout using Docker](#grout-using-docker)
|
82 | 84 | - [How Grout works](#how-grout-works)
|
83 | 85 | - [Self-hosted Grout](#self-hosted-grout)
|
@@ -1443,6 +1445,55 @@ grout https://localhost:8080 custom.example.com --wildcard
|
1443 | 1445 | 2024-08-05 18:25:03,159 - setup - Grouting https://*.custom.domain.com
|
1444 | 1446 | ```
|
1445 | 1447 |
|
| 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 | + |
1446 | 1497 | ## Grout using Docker
|
1447 | 1498 |
|
1448 | 1499 | ```console
|
|
0 commit comments