diff options
author | cflip <cflip@cflip.net> | 2023-05-29 22:13:12 -0600 |
---|---|---|
committer | cflip <cflip@cflip.net> | 2023-05-29 22:23:21 -0600 |
commit | 775c4157994ee0ebe9bd951a99bc5d7558128ba4 (patch) | |
tree | e6bbfea51cf0c66e909e9cd6bd3f7c0747b14ebc /net.c | |
parent | fca0a3d5d8ea1e9af4411ef03181b4c23534474b (diff) |
Hacks to make it possible to serve PHP pages
The most significant change is that the functions for reading a file and
such write directly to the socket instead of attempting to fill buffers.
Diffstat (limited to 'net.c')
-rw-r--r-- | net.c | 19 |
1 files changed, 5 insertions, 14 deletions
@@ -53,10 +53,7 @@ int initialize_server(int port) void handle_connection(int connfd) { - char *content_buf; - size_t content_len, response_len; - - char resbuf[CFWS_MAX_RESPONSE]; + const char *header = "HTTP/1.1 200 OK\r\n"; char readbuf[CFWS_MAXREAD]; struct http_request req; @@ -65,17 +62,11 @@ void handle_connection(int connfd) req = http_parse_request(readbuf); - content_len = file_read(req.uri, &content_buf); - if (content_len == 0) { - const char *msg = "Could not find the specified file."; - response_len = http_build_response(resbuf, - HTTP_RESPONSE_NOTFOUND, msg, strlen(msg)); - } else { - response_len = http_build_response(resbuf, HTTP_RESPONSE_OK, - content_buf, content_len); - free(content_buf); + write(connfd, header, strlen(header)); + if (file_handle_request(&req, connfd) != 0) { + const char *msg = "\r\nCould not find the specified file."; + write(connfd, msg, strlen(msg)); } - write(connfd, resbuf, response_len); http_free_request(&req); } |