swisspol/GCDWebServer

addGETHandler and overlapping paths

Closed this issue · 1 comments

This is an ongoing investigation, not an issue. Wondering if there are tricks required to add multiple addGETHandlerForBasePath where basePaths could be matched by one URL? That is to say: map /a/ to one handler and map / to another, in the hope that URLs such as /a/b/c would be processed by the first handler and not the second.

I cannot seem to mount multiple locations / and /a/ on the same GCDWebServer instance.

Oh, I totally see what's going on now. After reviewing GCDWebServer/Core/GCDWebServerConnection, the handler assignment is given to the first handler that returns a non-nil from _handler.matchBlock(), which depends on the insertion order of the handlers. Elsewhere I see that the most recently inserted handler is inserted at position zero of the handlers array.

For my own case, I would need to addGETHandler( forBasePath: "/", ...) followed by the more specific addGETHandler( forBasePath: "/a/", ...). I did a simple sort of my location collection using location.length as a sort comparator (the more generic locations inserted prior to less generic), and it is all good. Closing this issue.