From 0caf047c3c1ecf34a47061951e838d05574dbd6c Mon Sep 17 00:00:00 2001 From: Nakidai Date: Wed, 25 Sep 2024 00:57:51 +0300 Subject: Some new things - Remove debug "Got request!" string - Add \0 on the end of path - Send 404 if nobody served the request --- requestHandler.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/requestHandler.c b/requestHandler.c index da022dd..5781218 100644 --- a/requestHandler.c +++ b/requestHandler.c @@ -9,6 +9,7 @@ static const char *ok = "HTTP/1.0 200 OK\r\n"; +static const char *notfound = "HTTP/1.0 404 Not found\r\n"; static const char *not_implemented = "HTTP/1.0 501 Not implemented\r\n"; static const char *content_length = "Content-Length: %d\r\n"; @@ -39,8 +40,6 @@ void CPTC_requestHandler(int fd) goto end; } - printf("Got request!\n%s\n", buffer); - method = buffer[0]; if (method != CPTC_GET && method != CPTC_HEAD) { @@ -49,10 +48,9 @@ void CPTC_requestHandler(int fd) } path = strchr(buffer, ' ') + 1; - for (int i = 0; i < strchr(path, ' ') - path; ++i) - putchar(*(path + i)); - putchar('\n'); - if (strchr(path, ' ') - path == 1) + *strchr(path, ' ') = '\0'; + puts(path); + if (strlen(path) == 1) { send(fd, ok, strlen(ok), 0); char *length = malloc(sizeof(*length) * 32); @@ -65,6 +63,8 @@ void CPTC_requestHandler(int fd) goto end; } + send(fd, notfound, strlen(notfound), 0); + end: free(buffer); } -- cgit 1.4.1