Skip to content

Commit

Permalink
Add trim_querystring function + autotrim in url getter
Browse files Browse the repository at this point in the history
  • Loading branch information
Ernest1338 committed Sep 23, 2023
1 parent 608c95f commit 1171169
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions cmicroweb.h
Original file line number Diff line number Diff line change
Expand Up @@ -186,6 +186,9 @@ char **template_new(char *file_name);
// FIXME: added by me
char *template_render(char **template_instance, char **context);

// FIXME: added by me
void trim_querystring(char* s);

// Returns the query string of the full request target as it was read from
// the HTTP request line. Returns an empty string if there's no query
// string.
Expand Down Expand Up @@ -1338,6 +1341,8 @@ char *http_request_path(http_request_t* request) {
path.buf = target.buf;
path.len = q - target.buf;
char *url = strtok(path.buf, " ");
// auto trim query strings from the url (get it by using http_request_querystring(request) in the handler function)
trim_querystring(url);
return url;
}

Expand Down Expand Up @@ -1412,6 +1417,10 @@ char *template_render(char **template_instance, char **context) {
return render;
}

void trim_querystring(char* s) {
strtok(s, "?");
}

http_string_t http_request_querystring(http_request_t* request) {
http_string_t query = {0, 0};
http_string_t target = http_request_target(request);
Expand Down

0 comments on commit 1171169

Please sign in to comment.