From 432f7792d12dadc3adb605c018176bbc7359b503 Mon Sep 17 00:00:00 2001 From: ame Date: Tue, 12 Aug 2025 21:54:57 -0500 Subject: support percent encoding --- src/net.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) (limited to 'src/net.c') diff --git a/src/net.c b/src/net.c index 713e56a..2766781 100644 --- a/src/net.c +++ b/src/net.c @@ -678,7 +678,7 @@ void* handle_client(void *_arg){ if(val == -2) net_error(client_fd, 414); if(val >= 0){ - str* sk = (str*)parray_get(table, "Path"); + str* path = (str*)parray_get(table, "Path"); str* sR = (str*)parray_get(table, "Request"); str* sT = (str*)parray_get(table, "Content-Type"); str* sC = (str*)parray_get(table, "Cookie"); @@ -693,13 +693,22 @@ void* handle_client(void *_arg){ sprintf(portc, "%i", args->port); str* aa = str_init(portc); - str_push(aa, sk->c); + str* decoded_path; + int decoded_err = percent_decode(path, &decoded_path); + larray_t* params = NULL; + parray_t* v = NULL; - larray_t* params = larray_init(); - parray_t* v = route_match(paths, aa->c, ¶ms); - - if(sT != NULL) - rolling_file_parse(L, &files_idx, &body_idx, header + 4, sT, bite - header_eof - 4, file_cont); + if(decoded_err == 1){ + net_error(client_fd, 400); + } else { + str_push(aa, decoded_path->c); + + params = larray_init(); + v = route_match(paths, aa->c, ¶ms); + + if(sT != NULL) + rolling_file_parse(L, &files_idx, &body_idx, header + 4, sT, bite - header_eof - 4, file_cont); + } str_free(aa); if(v != NULL){ -- cgit v1.2.3