Hi,
I am playing around with Tufao (I contributed peerAddress() and
peerPort() to WebSockets). I am quite liking it :-)
Now I am experimenting with the request router. I understand the map()
method, and the fact that a few standard handlers already exist, such
as HttpFileServer.
I think what is missing is a URL rewrite method. Classic example is
mapping "/" to ''index.html". In my understanding, the only way to do
that in Tufao is writing a custom handler, like is done in examples/
sessionusage/roothandler.cpp. I find it cumbersome to write a class
just to map "/" to "index.html" :-)
I propose to add a method, rewrite(), to the request router:
rewrite(const QRegExp& path, const char* to)
(or maybe with QArray arguments for consistency). The client code
should call it _before_ any map() calls and in any case in the
internal logic, all the rewrites should happen before entering the map
rules.
Example:
Tufao::HttpServerRequestRouter router;
Tufao::HttpFileServer fileServer("public");
router.rewrite(QRegExp("^/$"), "/index.html");
router.map(QRegExp(""), &fileServer);
router.map(QRegExp(""), &handle404);
A request for "
http://example.com/" would get a reply with the
contents of public/index.html
What do you think?
marco.m