...
 
Commits (2)
......@@ -18,7 +18,7 @@
#include "http.h"
#define PORT 26887
#define PORT 26885
#define DEBUG 0
#define TRUE 1
......@@ -32,6 +32,8 @@ void getRequest(int clientfd, GrowthBuffer *request);
int checkFile(char *fileName);
void serveFile(int clientfd, const char *path);
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
......@@ -121,18 +123,9 @@ int handle_client(int clientfd) {
char *basicHeader = "HTTP/1.1 200 OK\r\n\r\n";
appendBuffer(&response, basicHeader, strlen(basicHeader));
write(clientfd, response.array, strlen(response.array));
FILE *fp;
size_t numBytesReadFile;
fp = fopen(path, "r");
char fileBuff[1024];
if (fp) {
printf("\nGot a fp\n");
while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) {
printf("%s", fileBuff);
write(clientfd, fileBuff, strlen(fileBuff));
}
if (verb == HTTP_GET) {
serveFile(clientfd, path);
}
fclose(fp);
} else {
char *basicHeader = "HTTP/1.1 404 Not Found\r\n\r\n";
appendBuffer(&response, basicHeader, strlen(basicHeader));
......@@ -149,6 +142,20 @@ int handle_client(int clientfd) {
#endif
}
void serveFile(int clientfd, const char *path) {
FILE *fp;
size_t numBytesReadFile;
fp = fopen(path, "r");
char fileBuff[1024];
if (fp) {
printf("\nGot a fp\n");
while ((numBytesReadFile = fread(fileBuff, 1023, 1, fp)) > 0) {
write(clientfd, fileBuff, strlen(fileBuff));
}
}
fclose(fp);
}
void getRequest(int clientfd, GrowthBuffer *request) {
struct pollfd pollfd = {
.fd = clientfd,
......