diff options
| author | Nakidai <nakidai@disroot.org> | 2024-12-16 00:23:02 +0300 |
|---|---|---|
| committer | Nakidai <nakidai@disroot.org> | 2024-12-16 00:23:02 +0300 |
| commit | 820203c352d2af7318e67640282a69ed41598f93 (patch) | |
| tree | 4d25e81891ce637750ac79a3e0784f058fc9e60f | |
| parent | cbe431ff5c32a69961fb8813ebdf66be6b529bae (diff) | |
| download | cptc-820203c352d2af7318e67640282a69ed41598f93.tar.gz cptc-820203c352d2af7318e67640282a69ed41598f93.zip | |
Make cptc use LibHTTPC_readRequest
| -rw-r--r-- | requestHandler.c | 27 |
1 files changed, 14 insertions, 13 deletions
diff --git a/requestHandler.c b/requestHandler.c index 0780618..9cf802c 100644 --- a/requestHandler.c +++ b/requestHandler.c @@ -2,6 +2,7 @@ #include "cptc.h" +#include <errno.h> #include <ctype.h> #include <stdbool.h> #include <stdio.h> @@ -42,25 +43,25 @@ void CPTC_requestHandler(int fd, int n) char raw_request[512]; char filenamebuf[64]; char raw_response[512], *responseadd = raw_response; - ssize_t received = recv(fd, raw_request, sizeof(raw_request), 0); FILE *fp = NULL; enum LibHTTPC_Method method; struct LibHTTPC_Request request = {0}; - if (received == -1) + if (LibHTTPC_readRequest(fd, &request, raw_request, sizeof(raw_request)) == NULL) { - perror("recv()"); - return; - } - - if (LibHTTPC_loadRequest(&request, raw_request) == NULL) - { - res = LibHTTPC_writeResponse( - fd, &(struct LibHTTPC_Response){.status = LibHTTPC_Status_BAD_REQUEST} - ); - if (res) - perror("send()"); + if (errno) + { + perror("recv()"); + } + else + { + res = LibHTTPC_writeResponse( + fd, &(struct LibHTTPC_Response){.status = LibHTTPC_Status_BAD_REQUEST} + ); + if (res) + perror("send()"); + } return; } |