Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

grout host header & dynamic routing doc #1490

Merged
merged 3 commits into from
Oct 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@
- [Grout Authentication](#grout-authentication)
- [Grout Paths](#grout-paths)
- [Grout Wildcard Domains](#grout-wildcard-domains)
- ["Host" Header Based Wildcard Routing](#grout-wildcard-domain-routing-based-upon-host-header)
- ["Dynamic" Routing](#grout-client-plugin)
- [Grout using Docker](#grout-using-docker)
- [How Grout works](#how-grout-works)
- [Self-hosted Grout](#self-hosted-grout)
Expand Down Expand Up @@ -1443,6 +1445,55 @@ grout https://localhost:8080 custom.example.com --wildcard
2024-08-05 18:25:03,159 - setup - Grouting https://*.custom.domain.com
```

## Grout Wildcard Domain Routing Based Upon "Host" Header

> Only available with `--wildcard`

Along with the default route you can also provide additional routes which takes precedence when the host field matches. Example:

```console
grout https://localhost:8080 custom.example.com \
--wildcard \
--tunnel-route-url stream.example.com=http://localhost:7001
```

You can provide multiple custom routes by repeating this flag.

## Grout Client Plugin

`GroutClientBasePlugin` allows you to dynamically route traffic to different upstreams. Below is a simple implementation with some description about how to use it.

```python
class GroutClientPlugin(GroutClientBasePlugin):

def resolve_route(
self,
route: str,
request: HttpParser,
origin: HostPort,
server: HostPort,
) -> Tuple[Optional[str], HttpParser]:
print(request, origin, server, '->', route)
print(request.header(b'host'), request.path)
#
# Here, we send traffic to localhost:7001 irrespective
# of the original "route" value provided to the grout
# client OR any custom host:upstream mapping provided
# through the --tunnel-route-url flags (when using
# --wildcard).
#
# Optionally, you can also strip path before
# sending traffic to upstrem, like:
# request.path = b"/"
#
# To drop the request, simply return None for route
# return None, request
#
return 'http://localhost:7001', request
```

See [grout_client.py](https:/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.

## Grout using Docker

```console
Expand Down
Loading