I have a weird situation where I have to serve HTTP and HTTPS on the same port, and when HTTP connections come in, serve the response as HTTP, but when HTTPS connections come in, serve the response as HTTPS. When I attempt to do this with the configuration below:
How would I start doing this (i.e. what would it need to do)? I can’t find any docs specifically about listener wrappers, only the other types of plugins. (and I don’t see any examples of AddListenerMiddleware in the v1 branch)
An efficient multiplexer is hard, though. It will require reading a few bytes to know if it is a TLS handshake (make sure to consider TLS 1.3 as well) and then handle accordingly.
Of course, yours will probably have an Accept() method that reads a few bytes from the net.Conn, then decides whether to initiate a TLS handshake or not. You might actually have to implement both Listener.Accept() and Conn.Read() methods… I did something similar in v1 here: caddy/mitm.go at v1 · caddyserver/caddy · GitHub and caddy/mitm.go at v1 · caddyserver/caddy · GitHub – but maybe yours won’t have to be so complex.