diff --git a/server/request_handling.c b/server/request_handling.c index 6b3e909..de44dfb 100644 --- a/server/request_handling.c +++ b/server/request_handling.c @@ -124,7 +124,7 @@ enum file_result get_file_from_uri(const char *uri, struct requested_file *req_f return RESULT_NOT_FILE; } - FILE *open_file = fopen(resource, "r"); + FILE *open_file = fopen(resource, "rb"); if (open_file == NULL) { return RESULT_IO_ERROR; } diff --git a/server/socket_server.c b/server/socket_server.c index 35303f1..a56e58a 100644 --- a/server/socket_server.c +++ b/server/socket_server.c @@ -178,8 +178,8 @@ static int send_headers(int status_code, int client_socket, long content_length) */ static int send_file(int client_fd, struct requested_file file) { char *buffer = malloc(FILE_BUFFER_SIZE * sizeof(char)); - while (fgets(buffer, FILE_BUFFER_SIZE, file.file) != NULL) { - int bytes_read = strlen(buffer); + int bytes_read; + while ((bytes_read = fread(buffer, sizeof(char), FILE_BUFFER_SIZE, file.file)) != 0) { int send_result = send(client_fd, buffer, bytes_read, 0); if (send_result == -1) { free(buffer);