Mercurial
comparison seobeo/s_router.c @ 92:655ea0b661fd
[Seobeo] Added few endpoints for handling files. [Dowa] Added few functions for random number and generating uuids
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Fri, 02 Jan 2026 17:47:10 -0800 |
| parents | 5710108c949e |
| children |
comparison
equal
deleted
inserted
replaced
| 91:19cccf6e866a | 92:655ea0b661fd |
|---|---|
| 148 if (p_content_type_kv) | 148 if (p_content_type_kv) |
| 149 { | 149 { |
| 150 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; | 150 content_type = ((Seobeo_Request_Entry*)p_content_type_kv)->value; |
| 151 } | 151 } |
| 152 | 152 |
| 153 // Check for custom content-length (for binary data) | |
| 154 size_t body_length = strlen(body); | |
| 155 void *p_content_length_kv = Dowa_HashMap_Get_Ptr(p_response_map, "content-length"); | |
| 156 if (p_content_length_kv) | |
| 157 { | |
| 158 const char *content_length_str = ((Seobeo_Request_Entry*)p_content_length_kv)->value; | |
| 159 body_length = atoi(content_length_str); | |
| 160 } | |
| 161 | |
| 153 // All other types are default thoguht to be headers. | 162 // All other types are default thoguht to be headers. |
| 154 char *header = Dowa_Arena_Allocate(p_arena, 4096); | 163 char *header = Dowa_Arena_Allocate(p_arena, 4096); |
| 155 Seobeo_Web_Header_Generate(header, status, content_type, strlen(body)); | 164 Seobeo_Web_Header_Generate(header, status, content_type, body_length); |
| 156 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) | 165 for (int i = 0; i < Dowa_Array_Length(p_response_map); i++) |
| 157 { | 166 { |
| 158 if ( | 167 if ( |
| 159 strstr(p_response_map[i].key, "status") || | 168 strstr(p_response_map[i].key, "status") || |
| 160 strstr(p_response_map[i].key, "body") || | 169 strstr(p_response_map[i].key, "body") || |
| 161 strstr(p_response_map[i].key, "content-type") | 170 strstr(p_response_map[i].key, "content-type") || |
| 171 strstr(p_response_map[i].key, "content-length") // Skip custom content-length | |
| 162 ) | 172 ) |
| 163 continue; | 173 continue; |
| 164 | 174 |
| 165 int32 current_header_len = strlen(header); | 175 int32 current_header_len = strlen(header); |
| 166 char *temp = malloc(sizeof(char) * 1024); | 176 char *temp = malloc(sizeof(char) * 1024); |
| 168 memcpy(&header[current_header_len - 2 /* \r\n */], temp, strlen(temp)); | 178 memcpy(&header[current_header_len - 2 /* \r\n */], temp, strlen(temp)); |
| 169 free(temp); | 179 free(temp); |
| 170 } | 180 } |
| 171 | 181 |
| 172 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); | 182 Seobeo_Handle_Queue(p_handle, (uint8_t*)header, strlen(header)); |
| 173 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, strlen(body)); | 183 Seobeo_Handle_Queue(p_handle, (uint8_t*)body, body_length); // Use actual body length |
| 174 Seobeo_Handle_Flush(p_handle); | 184 Seobeo_Handle_Flush(p_handle); |
| 175 } | 185 } |
| 176 | 186 |
| 177 void Seobeo_Router_Destroy() | 187 void Seobeo_Router_Destroy() |
| 178 { | 188 { |