diff options
author | cflip <cflip@cflip.net> | 2023-05-30 12:31:34 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2023-05-30 12:31:34 -0600 |
commit | 8dbdf132ea82a567d7cef856469fd47c511b4191 (patch) | |
tree | 66d87095b94b90a1a66946c0b514cfbe75ae1f10 /http.c | |
parent | 775c4157994ee0ebe9bd951a99bc5d7558128ba4 (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.c | 13 |
1 files changed, 11 insertions, 2 deletions
@@ -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); } |