Open c9s opened 9 years ago
@karantin2020 just to confirm, are the items above completed?
Routes contain only slug names:
struct _R3Route {
char * path;
int path_len;
char **slugs;
int slugs_len;
int slugs_cap;
...
typedef struct {
str_array * vars;
const char * path; // current path to dispatch
int path_len; // the length of the current path
int request_method; // current request method
void * data; // R3Route ptr
char * host; // the request host
int host_len;
char * remote_addr;
int remote_addr_len;
} match_entry;
typedef struct _str_array {
char **slugs;
int slugs_len;
char **tokens;
int len;
int cap;
} str_array;
Access to slug names and it's values is through match_entry->vars
.
Slug names are pointers to routers field slugs
. They do not copy by value and do not create again.
The second point was not realized full.
...so we can iterate the slugs in the matched route
- it is incorrect way to access slugs. Routes created only once and there is no need to change it in life time. Because slug values depend on every match path it is better to save that values in match_entry
struct.
So iterate slugs with match_entry->vars
.
For details see examples/routing.c
.