Mercurial
diff seobeo/s_router.c @ 79:5710108c949e
[Seobeo] Added Redirect logic.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Thu, 01 Jan 2026 05:57:03 -0800 |
| parents | e7bf9e002850 |
| children | 655ea0b661fd |
line wrap: on
line diff
--- a/seobeo/s_router.c Wed Dec 31 15:07:43 2025 -0800 +++ b/seobeo/s_router.c Thu Jan 01 05:57:03 2026 -0800 @@ -28,8 +28,6 @@ route.method = strdup(method); route.path_pattern = strdup(path_pattern); route.handler = handler; - - // save it as global variable route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL); route.segment_count = Dowa_Array_Length(route.path_segments); route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count); @@ -112,9 +110,10 @@ return NULL; } -void Seobeo_Router_Send_Response(Seobeo_Handle *p_handle, - Seobeo_Request_Entry *p_response_map, - Dowa_Arena *p_arena) +void Seobeo_Router_Send_Response( + Seobeo_Handle *p_handle, + Seobeo_Request_Entry *p_response_map, + Dowa_Arena *p_arena) { if (p_response_map == NULL) { @@ -151,8 +150,24 @@ content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; } - char *header = Dowa_Arena_Allocate(p_arena, 1024); + // All other types are default thoguht to be headers. + char *header = Dowa_Arena_Allocate(p_arena, 4096); Seobeo_Web_Header_Generate(header, status, content_type, strlen(body)); + for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) + { + if ( + strstr(p_response_map[i].key, "status") || + strstr(p_response_map[i].key, "body") || + strstr(p_response_map[i].key, "content-type") + ) + continue; + + int32 current_header_len = strlen(header); + char *temp = malloc(sizeof(char) * 1024); + sprintf(temp, "%s: %s\r\n\r\n", p_response_map[i].key, p_response_map[i].value); + memcpy(&header[current_header_len - 2 /* \r\n */], temp, strlen(temp)); + free(temp); + } Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); Seobeo_Handle_Queue(p_handle, (uint8_t*)body, strlen(body));