fix string and pointer bugs to actually send 404

This commit is contained in:
Nayan
2025-05-08 17:37:23 -04:00
parent ddf6f8812f
commit b12cfd2c17
5 changed files with 12 additions and 9 deletions

View File

@@ -3,7 +3,7 @@
void parse_http_request(char* request, int length, struct http_request* req);
void debug_print_request(char* request);
void handle_request(char* request, int length, char* response,
void handle_request(char* request, int length, char** response,
size_t* response_length) {
// Terminate request with EOF so strtok stops at end of string
request[length] = EOF;
@@ -13,12 +13,12 @@ void handle_request(char* request, int length, char* response,
// debug_print_request(request);
printf("parsing request ---------\n");
// printf("parsing request ---------\n");
// Parse request into struct
http_request* req = create_http_request();
parse_http_request(request, length, req);
print_http_request(req);
printf("---------\n");
// print_http_request(req);
// printf("---------\n");
// request_info_print(req);
// free_http_request(req);
@@ -31,8 +31,9 @@ void handle_request(char* request, int length, char* response,
// Convert response to string
char* response_string = response_to_string(res);
// Copy string to response
response = (char*)malloc(strlen(response_string) + 1);
strcpy(response, response_string);
char* responsestr = (char*)malloc(strlen(response_string) + 1);
strcpy(responsestr, response_string);
*response = responsestr;
// Set response length
*response_length = strlen(response_string);
// Free response