summaryrefslogtreecommitdiff
path: root/http.c
diff options
context:
space:
mode:
authorcflip <cflip@cflip.net>2023-05-30 12:31:34 -0600
committercflip <cflip@cflip.net>2023-05-30 12:31:34 -0600
commit8dbdf132ea82a567d7cef856469fd47c511b4191 (patch)
tree66d87095b94b90a1a66946c0b514cfbe75ae1f10 /http.c
parent775c4157994ee0ebe9bd951a99bc5d7558128ba4 (diff)
Refactor response building code
This new strategy involves finding the local file path for the given URI, determining what method to use to fulfill the request (read file from disk, use php-cgi, or error), then it writes the response to the client socket.
Diffstat (limited to 'http.c')
-rw-r--r--http.c13
1 files changed, 11 insertions, 2 deletions
diff --git a/http.c b/http.c
index 40a2b82..41a0435 100644
--- a/http.c
+++ b/http.c
@@ -4,6 +4,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
struct http_request http_parse_request(const char *reqstr)
{
@@ -30,7 +31,15 @@ void http_free_request(struct http_request *req)
free(req->uri);
}
-int http_build_response(char *res, enum http_res_code code, const char *msg, size_t msglen)
+static const char *response_msg[2] = {
+ "200 OK",
+ "404 Not Found"
+};
+
+void http_response_statusline(enum http_res_code status_code, int sockfd)
{
- return snprintf(res, CFWS_MAX_RESPONSE, "HTTP/1.1 200 OK\r\n%.*s\r\n", msglen, msg);
+ char statusline[64];
+ int len;
+ len = snprintf(statusline, 64, "HTTP/1.1 %s\r\n", response_msg[status_code]);
+ write(sockfd, statusline, len);
}