From 26937d4abac445505c8ce68023da92fb50cd1d30 Mon Sep 17 00:00:00 2001 From: Nayan <33187059+GShadow5@users.noreply.github.com> Date: Tue, 6 May 2025 16:57:41 -0400 Subject: [PATCH] return filename to client, and add content length to fix indefinite hang bug --- request_handler.c | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/request_handler.c b/request_handler.c index aaadff4..a9f5cfb 100644 --- a/request_handler.c +++ b/request_handler.c @@ -55,7 +55,25 @@ void handle_request(char* request, int length, char* response, // Create reponse string ptr_temp = response; - char* temp = "HTTP/1.1 200 OK\nContent-Type: text/html\n\n"; + char* temp = + "HTTP/1.1 200 OK\r\nContent-Type: text/html \r\nContent-Length: "; + while (*temp != '\0') { + *ptr_temp = *temp; + ptr_temp++; + temp++; + } + // Put content length in the html response + int content_length = strlen(filename); + char content_length_str[10]; + sprintf(content_length_str, "%d", content_length); + temp = (char*)&content_length_str; + while (*temp != '\0') { + *ptr_temp = *temp; + ptr_temp++; + temp++; + } + // Terminate header + temp = "\r\n\r\n\0"; while (*temp != '\0') { *ptr_temp = *temp; ptr_temp++;