diff --git a/src/http.c b/src/http.c index 701d8fd..a3062cc 100644 --- a/src/http.c +++ b/src/http.c @@ -199,14 +199,19 @@ char *c_simple_http_strip_path(const char *path, size_t path_size) { } } - if (idx >= path_size || path[idx] == 0) { - return NULL; - } - char *stripped_path = malloc(idx + 1); memcpy(stripped_path, path, idx); stripped_path[idx] = 0; + // Strip trailing '/'. + while (idx-- > 1) { + if (stripped_path[idx] == '/' || stripped_path[idx] == 0) { + stripped_path[idx] = 0; + } else { + break; + } + } + return stripped_path; } diff --git a/src/http.h b/src/http.h index 411ff6b..766214b 100644 --- a/src/http.h +++ b/src/http.h @@ -52,7 +52,7 @@ char *c_simple_http_request_response( /// Takes a PATH string and returns a "bare" path. /// This will simply omit the first instance of "?" or "#" and the rest of the -/// string. +/// string. This will also remove trailing "/" characters. /// Must be free'd if returns non-NULL. char *c_simple_http_strip_path(const char *path, size_t path_size);