c9s / r3

libr3 is a high-performance path dispatching library. It compiles your route paths into a prefix tree (trie). By using the constructed prefix trie in the start-up time, you may dispatch your routes with efficiency
http://c9s.github.com/r3/bench.html
MIT License
813 stars 83 forks source link

feature: recursive methods to match multiple rules. #120

Closed membphis closed 5 years ago

membphis commented 5 years ago

This is a mini test case, it should be a bug, I think it should match all current routing rules.

Do you agree with this? @c9s

    R3Node * tree = r3_tree_create(3);

    int route_data1 = 1;
    int route_data2 = 2;

    // insert the R3Route path into the router tree
    r3_tree_insert_routel(tree, METHOD_GET | METHOD_POST, "/api", sizeof("/api") - 1, &route_data1 );
    r3_tree_insert_routel(tree, METHOD_GET | METHOD_POST, "/api/v1", sizeof("/api/v1") - 1, &route_data2 );
    char *errstr = NULL;
    int err = r3_tree_compile(tree, &errstr);
    if(err) {
        printf("%s\n",errstr);
        free(errstr);
        return 1;
    }

    char *path = "/api/v1/user";
    match_entry *e = match_entry_createl(path, strlen(path));

    R3Node *n;
    R3Route *r;
    n = r3_tree_matchl(tree, e->path.base, e->path.len, e);
    if (n == NULL) {
        printf("failed to match\n");     
        return 1;
    }

    ...
$ gcc -g test.c -lr3 && LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH ./a.out
failed to match
membphis commented 5 years ago

that is not a bug, close it.