diff options
author | Anton Kling <anton@kling.gg> | 2024-10-15 18:04:54 +0200 |
---|---|---|
committer | Anton Kling <anton@kling.gg> | 2024-10-16 18:01:19 +0200 |
commit | 6d4f0e917f638c0ab53d847037938d83497f53ea (patch) | |
tree | a0074ae2d1e1a8bb38de0a74ecb16a47e02bb624 | |
parent | 390ec7b43ba1bd4def5397ecece7a826e9e40146 (diff) |
httpd: Bug fix for not handling error code 400 properly
-rw-r--r-- | userland/httpd/httpd.c | 28 |
1 files changed, 13 insertions, 15 deletions
diff --git a/userland/httpd/httpd.c b/userland/httpd/httpd.c index 7bb4958..e65dcf8 100644 --- a/userland/httpd/httpd.c +++ b/userland/httpd/httpd.c @@ -119,27 +119,25 @@ void parse_incoming_request(struct http_request *request) { request->file_fd = -1; request->is_directory = 0; - if (!sv_eq(method, C_TO_SV("GET"))) { - request->status_code = 400; - return; - } - - // The difference in buffer size is intentional to be able to append - // '/index.html' later char path_buffer[256 + 11]; - sv_to_cstring_buffer(path, path_buffer, 256); - request_try_file(request, path_buffer); - - if (request->is_directory) { - strcat(path_buffer, "/index.html"); + if (sv_eq(method, C_TO_SV("GET"))) { + // The difference in buffer size is intentional to be able to append + // '/index.html' later + sv_to_cstring_buffer(path, path_buffer, 256); request_try_file(request, path_buffer); - return; + + if (request->is_directory) { + strcat(path_buffer, "/index.html"); + request_try_file(request, path_buffer); + return; + } + } else { + request->status_code = 400; } + if (200 != request->status_code) { - printf("status_code: %d\n", request->status_code); const int tmp = request->status_code; sprintf(path_buffer, "/%3d.html", request->status_code); - printf("path_buffer: %s\n", path_buffer); request_try_file(request, path_buffer); request->status_code = tmp; } |