Hi All,
I’m using Cowboy 2.14.2 and would like to implement conditional request forwarding to an upstream server based on specific conditions (e.g., User-Agent header value).
Use case: When a request arrives with a specific User-Agent value (e.g., “XXXXXX”), I want Cowboy to act as a simple reverse proxy and forward the request to an upstream non-Erlang server, rather than handling it with my application logic.
Is there a built-in or recommended way to achieve this in Cowboy? Should I:
- Implement this logic in a middleware that intercepts requests before they reach my handlers?
- Use a custom handler that performs the HTTP proxying using an HTTP client like
gun? - Use a different approach altogether?
I would appreciate if someone could provide a code snippet or working example showing how to implement this.
Any guidance would be greatly appreciated.
Thanks,
. Erlang 28.1.1
. Ubuntu 24.04 LTS + macOS Tahoe 26.0.1
. rebar 3.25.1+build.5474.ref161b38cf on Erlang/OTP 28 Erts 16.1.1