Feature: Discard requests for unknown routers

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

404 page comes as a response for HTTP protocol. HTTP protocol does not describe an option to close the connection if you do not like it. You have to send back a response with a status code. And that's what traefik does.

While I understand that certain scenario exists where one might find what you want useful, I very much doubt this particular "feature" will ever end up in the official traefik binaries. You are of course free to modify your own version and re-compile it the way you like.

How about the possibility to define a service for this case instead?

So that everyone is able to do the actual implementation themselves to cover even more use cases.

You can create a catch-all router with a low priority.

2 Likes