From 703795c3f5a8db1399fb69f088e2d155590c40de Mon Sep 17 00:00:00 2001 From: Alex Hultman Date: Sun, 29 Dec 2019 22:36:57 +0100 Subject: [PATCH] Clean up router --- src/HttpRouter.h | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/HttpRouter.h b/src/HttpRouter.h index 9ab8032..23e5d56 100644 --- a/src/HttpRouter.h +++ b/src/HttpRouter.h @@ -24,9 +24,7 @@ #include #include #include -#include #include -#include #include #include #include @@ -37,12 +35,13 @@ namespace uWS { template struct HttpRouter { - - USERDATA userData; - + /* These are public for now */ std::vector methods = {"get", "post", "head", "put", "delete", "connect", "options", "trace", "patch"}; - /* 32-bit */ +private: + USERDATA userData; + + /* 32-bit handler id */ const static uint32_t HANDLER_MASK = 0x0fffffff; const static uint32_t HIGH_PRIORITY = 0xd0000000; const static uint32_t MEDIUM_PRIORITY = 0xe0000000; @@ -50,19 +49,24 @@ struct HttpRouter { static const unsigned int MAX_URL_SEGMENTS = 100; -private: /* Methods and their respective priority */ std::map priority; + /* List of handlers */ + std::vector> handlers; + + /* Current URL cache */ + std::string_view currentUrl; + std::string_view urlSegmentVector[MAX_URL_SEGMENTS]; + int urlSegmentTop; + + /* The matching tree */ struct Node { std::string name; std::vector> children; std::vector handlers; } root = {"rootNode"}; - /* List of handlers */ - std::vector> handlers; - /* Advance from parent to child, adding child if necessary */ Node *getNode(Node *parent, std::string child) { for (std::unique_ptr &node : parent->children) { @@ -100,10 +104,6 @@ private: } } routeParameters; - std::string_view currentUrl; - std::string_view urlSegmentVector[MAX_URL_SEGMENTS]; - int urlSegmentTop; - /* Set URL for router. Will reset any URL cache */ inline void setUrl(std::string_view url) { /* Remove / from input URL */ @@ -189,10 +189,6 @@ public: } } - void print() { - printNode(&root, 0); - } - std::pair getParameters() { return {routeParameters.paramsTop, routeParameters.params}; }