From: Christian Hofstaedtler Date: Tue, 28 Jan 2014 13:46:26 +0000 (+0100) Subject: webserver: document that URL registration order matters X-Git-Tag: rec-3.6.0-rc1~213^2~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=acfd888ce297220b200eb8f6522360d08680f533;p=pdns webserver: document that URL registration order matters While at it, cleanup ordering of routes. Doesn't actually matter for the existing routes. --- diff --git a/pdns/webserver.cc b/pdns/webserver.cc index e5980bf6c..f4bacade6 100644 --- a/pdns/webserver.cc +++ b/pdns/webserver.cc @@ -46,10 +46,14 @@ int WebServer::B64Decode(const std::string& strInput, std::string& strOutput) // route() makes no assumptions about the contents of variables except // that the following URL segment can't be part of the variable. // +// Note: ORDER of registration MATTERS: +// URLs that do a more specific match should come FIRST. +// // Examples: -// registerHandler("/", &index); -// registerHandler("/foo", &foo); // registerHandler("/foo//", &foobarbaz); +// registerHandler("/foo/", &foobar); +// registerHandler("/foo", &foo); +// registerHandler("/", &index); void WebServer::registerHandler(const string& url, HandlerFunction handler) { std::size_t pos = 0, lastpos = 0; diff --git a/pdns/ws.cc b/pdns/ws.cc index c03c48336..7a7498259 100644 --- a/pdns/ws.cc +++ b/pdns/ws.cc @@ -882,18 +882,18 @@ void StatWebServer::cssfunction(HttpRequest* req, HttpResponse* resp) void StatWebServer::launch() { try { - d_ws->registerHandler("/", boost::bind(&StatWebServer::indexfunction, this, _1, _2)); - d_ws->registerHandler("/style.css", boost::bind(&StatWebServer::cssfunction, this, _1, _2)); if(::arg().mustDo("experimental-json-interface")) { - registerApiHandler("/servers", &apiServer); - registerApiHandler("/servers/localhost", &apiServerDetail); registerApiHandler("/servers/localhost/config", &apiServerConfig); registerApiHandler("/servers/localhost/search-log", &apiServerSearchLog); - registerApiHandler("/servers/localhost/zones", &apiServerZones); registerApiHandler("/servers/localhost/zones/", &apiServerZoneDetail); + registerApiHandler("/servers/localhost/zones", &apiServerZones); + registerApiHandler("/servers/localhost", &apiServerDetail); + registerApiHandler("/servers", &apiServer); // legacy dispatch registerApiHandler("/jsonstat", boost::bind(&StatWebServer::jsonstat, this, _1, _2)); } + d_ws->registerHandler("/style.css", boost::bind(&StatWebServer::cssfunction, this, _1, _2)); + d_ws->registerHandler("/", boost::bind(&StatWebServer::indexfunction, this, _1, _2)); d_ws->go(); } catch(...) {