Read data as binary rather than strings
This commit is contained in:
parent
3582cc8b0d
commit
67ce81fe03
|
@ -124,7 +124,7 @@ enum file_result get_file_from_uri(const char *uri, struct requested_file *req_f
|
||||||
return RESULT_NOT_FILE;
|
return RESULT_NOT_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
FILE *open_file = fopen(resource, "r");
|
FILE *open_file = fopen(resource, "rb");
|
||||||
if (open_file == NULL) {
|
if (open_file == NULL) {
|
||||||
return RESULT_IO_ERROR;
|
return RESULT_IO_ERROR;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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) {
|
static int send_file(int client_fd, struct requested_file file) {
|
||||||
char *buffer = malloc(FILE_BUFFER_SIZE * sizeof(char));
|
char *buffer = malloc(FILE_BUFFER_SIZE * sizeof(char));
|
||||||
while (fgets(buffer, FILE_BUFFER_SIZE, file.file) != NULL) {
|
int bytes_read;
|
||||||
int bytes_read = strlen(buffer);
|
while ((bytes_read = fread(buffer, sizeof(char), FILE_BUFFER_SIZE, file.file)) != 0) {
|
||||||
int send_result = send(client_fd, buffer, bytes_read, 0);
|
int send_result = send(client_fd, buffer, bytes_read, 0);
|
||||||
if (send_result == -1) {
|
if (send_result == -1) {
|
||||||
free(buffer);
|
free(buffer);
|
||||||
|
|
Loading…
Reference in a new issue