You can read through Caddy’s reverseproxy package source, specifically the streaming.go file. That’s where we do the WebSockets handling.
I wonder if it would be possible for you to implement your Python stuff as a reverse_proxy transport instead of as its own handler directive. That way you could inherit all this functionality from the proxy handler and just forward the request where it needs to go with the protocol of your choice. That’s how php_fastcgi is implemented, which is a shortcut for a reverse_proxy handler with a fastcgi transport.
I like the idea of implementing the Python stuff as a new transport.
I’ve been taking a look at how reverseproxy and streaming.go are implemented.
One thing that is not clear to me is how could I modify the stream processing to catch websockets messages. Take in consideration that according to ASGI Spec I need to identify ws messages when interacting with a Python app.