For TCP connections I would like to have the ability to drop requests to undefined routers.
This topic is often misunderstood with the middleware Errorpage (https://docs.traefik.io/middlewares/errorpages).
However, this is not about reacting to the HTTP status code of an existing route, rather to change the behavior of how Traefik reacts to a non-existent router.
Current behavior is a response with the content "404 Not Found".
The origin of the behavior can be found in server_entrypoint_tcp.go
.
Since the default handler is used. See: http package - net/http - Go Packages
The handler is typically nil, in which case the DefaultServeMux is used.
DefaultServeMux
responds to this with NotFound
.
We have the possibility to change the behavior with a handler, so in this case we can simply close the connection.
A good reference (also with examples) I found in the following article: HandlerFunc, Handle and DefaultServeMux in Go