Tectu / malloy

A cross-platform C++20 library providing embeddable server & client components for HTTP and WebSocket.
BSD 3-Clause "New" or "Revised" License
66 stars 8 forks source link

fix: router needing server string in ctor #99

Closed 0x00002a closed 2 years ago

0x00002a commented 2 years ago

fixes: #68

This implements part of what I suggested in the issue while keeping the current behavior and features (namely different server string for subrouters). I'm not sure this is really desired functionality but since this is a fix I didn't want to remove functionality.

The router server string is now an optional argument of the ctor, if it is not specified then it is set by add_subrouter. This works because for a router to actually be used it is guaranteed to either be the root router, whose server string is set by the controller or as a subrouter that will eventually be added to root. This of course requires that it composes commutativity (i.e. the order of adding subrouter trees to the root doesn't matter), which I've added a test case for.

There are some drawbacks to this approach, the biggest of which is I think the lack of ability to change the string after construction. I made the setter private because I think the propagation is an implementation detail, and it would be weird to have the propagation just stop. One solution could be to remove the ability to preserve different server strings on subrouters and simply overwrite it rather than checking whether it has been set yet, which I like but removes the feature of different server strings per subrouter.