Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 78:e7bf9e002850 | 79:5710108c949e |
|---|---|
| 26 Seobeo_Route route = {0}; | 26 Seobeo_Route route = {0}; |
| 27 | 27 |
| 28 route.method = strdup(method); | 28 route.method = strdup(method); |
| 29 route.path_pattern = strdup(path_pattern); | 29 route.path_pattern = strdup(path_pattern); |
| 30 route.handler = handler; | 30 route.handler = handler; |
| 31 | |
| 32 // save it as global variable | |
| 33 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL); | 31 route.path_segments = Dowa_String_Split(path_pattern, "/", strlen(path_pattern), 1, NULL); |
| 34 route.segment_count = Dowa_Array_Length(route.path_segments); | 32 route.segment_count = Dowa_Array_Length(route.path_segments); |
| 35 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count); | 33 route.is_param = (boolean*)malloc(sizeof(boolean) * route.segment_count); |
| 36 | 34 |
| 37 for (size_t i = 0; i < route.segment_count; i++) | 35 for (size_t i = 0; i < route.segment_count; i++) |
| 110 } | 108 } |
| 111 | 109 |
| 112 return NULL; | 110 return NULL; |
| 113 } | 111 } |
| 114 | 112 |
| 115 void Seobeo_Router_Send_Response(Seobeo_Handle *p_handle, | 113 void Seobeo_Router_Send_Response( |
| 116 Seobeo_Request_Entry *p_response_map, | 114 Seobeo_Handle *p_handle, |
| 117 Dowa_Arena *p_arena) | 115 Seobeo_Request_Entry *p_response_map, |
| 116 Dowa_Arena *p_arena) | |
| 118 { | 117 { |
| 119 if (p_response_map == NULL) | 118 if (p_response_map == NULL) |
| 120 { | 119 { |
| 121 char *header = Dowa_Arena_Allocate(p_arena, 1024); | 120 char *header = Dowa_Arena_Allocate(p_arena, 1024); |
| 122 Seobeo_Web_Header_Generate(header, HTTP_INTERNAL_ERROR, "text/plain", 21); | 121 Seobeo_Web_Header_Generate(header, HTTP_INTERNAL_ERROR, "text/plain", 21); |
| 149 if (p_content_type_kv) | 148 if (p_content_type_kv) |
| 150 { | 149 { |
| 151 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; | 150 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; |
| 152 } | 151 } |
| 153 | 152 |
| 154 char *header = Dowa_Arena_Allocate(p_arena, 1024); | 153 // All other types are default thoguht to be headers. |
| 154 char *header = Dowa_Arena_Allocate(p_arena, 4096); | |
| 155 Seobeo_Web_Header_Generate(header, status, content_type, strlen(body)); | 155 Seobeo_Web_Header_Generate(header, status, content_type, strlen(body)); |
| 156 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) | |
| 157 { | |
| 158 if ( | |
| 159 strstr(p_response_map[i].key, "status") || | |
| 160 strstr(p_response_map[i].key, "body") || | |
| 161 strstr(p_response_map[i].key, "content-type") | |
| 162 ) | |
| 163 continue; | |
| 164 | |
| 165 int32 current_header_len = strlen(header); | |
| 166 char *temp = malloc(sizeof(char) * 1024); | |
| 167 sprintf(temp, "%s: %s\r\n\r\n", p_response_map[i].key, p_response_map[i].value); | |
| 168 memcpy(&header[current_header_len - 2 /* \r\n */], temp, strlen(temp)); | |
| 169 free(temp); | |
| 170 } | |
| 156 | 171 |
| 157 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); | 172 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); |
| 158 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, strlen(body)); | 173 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, strlen(body)); |
| 159 Seobeo_Handle_Flush(p_handle); | 174 Seobeo_Handle_Flush(p_handle); |
| 160 } | 175 } |