diff options
| author | Nakidai <nakidai@disroot.org> | 2024-09-25 00:57:51 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-09-25 00:57:51 +0300 |
| commit | 0caf047c3c1ecf34a47061951e838d05574dbd6c (patch) | |
| tree | f52cd65a2830219ce85952d15dadc2581975e7ee | |
| parent | a2fa006f2b20d0c1617eb29c87f3df3acbf94987 (diff) | |
| download | cptc-0caf047c3c1ecf34a47061951e838d05574dbd6c.tar.gz cptc-0caf047c3c1ecf34a47061951e838d05574dbd6c.zip | |
Some new things
- Remove debug "Got request!" string - Add \0 on the end of path - Send 404 if nobody served the request
| -rw-r--r-- | requestHandler.c | 12 |
1 files 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); } |