mholt / caddy-l4

Layer 4 (TCP/UDP) app for Caddy
Apache License 2.0
820 stars 67 forks source link

Feature request: `invoke` handler #211

Open legobeat opened 4 days ago

legobeat commented 4 days ago

It is often the case that we want to do some further handling of a request after termination with caddy-l4. One example would be using the caddy http module to match on HTTP headers, rewrite URLs, or conditionally forward to different downstreams.

We do have some existing overlap of functionality in the l4.http module but it doesn't seem desirable to start lifting over further "missing functionality" from caddy into l4, or as a user to fork it for this purpose.

Currently, I see two ways to achieve this without modifying caddy-l4:

  1. Putting caddy-l4 in listener_wrappers, wrapping downstream listeners
  2. Have a separate http app running on a local socket and have caddy-l4 dial it
    • This works fine and is relatively trivial to configure but is inefficient and ugly

If caddy-l4 adds support for an invoke handler matching the API of the http app and forwarding to named routes from other apps, it seems that we could get a nice middle-ground option which:

Possibly at some point later I could take a stab at an early implementation if I could get a sanity-check on the above assumptions and suggested approach.


Related:

mholt commented 4 days ago

Have a separate http app running on a local socket and have caddy-l4 dial it

  • This works fine and is relatively trivial to configure but is inefficient and ugly

A while ago I experimented with making a listener that can "pipe" data directly within the process, without the inefficiencies of re-dialing: https://github.com/caddyserver/caddy/pull/5040

It seems like that would go a long way to fulfilling the feature request?

legobeat commented 3 days ago

@mholt Oh yeah, that looks even better, if changes to Caddy itself is on the table!