Well then not only is haproxy unable to do that, it is also technically impossible.

This here:hdr_dom(host) -m beg test1.

Means: look for the HTTP-Header (in a HTTP Request) named “host” and check if its value begins with test1.

If there is no HTTP protocol, no HTTP request - then you cannot possibly access HTTP headers. And if there is a unknown protocol that is forwarded, not only don’t we know where to look for the header, but more likely there is probably no such header at all. For all intents and purposes there is not even an URL here.