]> granicus.if.org Git - pdns/commitdiff
webserver: document that URL registration order matters
authorChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 13:46:26 +0000 (14:46 +0100)
committerChristian Hofstaedtler <christian@hofstaedtler.name>
Tue, 28 Jan 2014 20:12:21 +0000 (21:12 +0100)
While at it, cleanup ordering of routes. Doesn't actually matter for
the existing routes.

pdns/webserver.cc
pdns/ws.cc

index e5980bf6c2a69c8f86a3c8407123a80c89c2263d..f4bacade629f1645fc6c8681b0b6995f8cbfbd63 100644 (file)
@@ -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/<bar>/<baz>", &foobarbaz);
+//   registerHandler("/foo/<bar>", &foobar);
+//   registerHandler("/foo", &foo);
+//   registerHandler("/", &index);
 void WebServer::registerHandler(const string& url, HandlerFunction handler)
 {
   std::size_t pos = 0, lastpos = 0;
index c03c483366474a2f4b5b767e770940e5f259ac51..7a7498259d467f4153d16c4698c074f9f18cd0d9 100644 (file)
@@ -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/<id>", &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(...) {