aboutsummaryrefslogtreecommitdiff
path: root/src/routing.c
diff options
context:
space:
mode:
authorfrosty <gabriel@bwaaa.monster>2026-04-10 17:09:41 -0400
committerfrosty <gabriel@bwaaa.monster>2026-04-10 17:09:41 -0400
commit8016cbdb7c190e6664a50560e3c8ea58f00fb31b (patch)
treedebaf00a4d04372a881513b4f9e3afaf4ef35c85 /src/routing.c
parent3fab89ecf8f4c664477a82add660d28db87357b4 (diff)
parent80caa6b317fdde4f3223648da709d184438a5a08 (diff)
downloadbeaker-8016cbdb7c190e6664a50560e3c8ea58f00fb31b.tar.gz
Merge branch 'indev'
Diffstat (limited to 'src/routing.c')
-rw-r--r--src/routing.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/src/routing.c b/src/routing.c
index d5d3969..1ae4ce9 100644
--- a/src/routing.c
+++ b/src/routing.c
@@ -322,16 +322,26 @@ bool serve_static_file_with_mime(const char *request_path_relative_to_static, co
char file_buffer[BUFFER_SIZE];
size_t bytes_read;
+ bool send_error = false;
- while ((bytes_read = fread(file_buffer, 1, sizeof(file_buffer), fp)) > 0) {
+ clearerr(fp);
+ while (!send_error && !feof(fp) && !ferror(fp) && (bytes_read = fread(file_buffer, 1, sizeof(file_buffer), fp)) > 0) {
if (send(current_client_socket, file_buffer, bytes_read, 0) < 0) {
perror("Error sending static file content");
fprintf(stderr, "[ERROR] serve_static_file_with_mime: Failed to send content for '%s'.\n",
full_static_path);
- break;
+ send_error = true;
}
}
+ if (ferror(fp)) {
+ perror("Error reading static file");
+ fprintf(stderr, "[ERROR] serve_static_file_with_mime: Failed to read '%s'.\n",
+ full_static_path);
+ fclose(fp);
+ return true;
+ }
+
fclose(fp);
return true;
}