comparison seobeo/s_web.c @ 184:8c74204fd362

[MD to HTML] Updated so it can be used through readme to html
author MrJuneJune <me@mrjunejune.com>
date Fri, 23 Jan 2026 22:20:35 -0800
parents a8976a008a9d
children 8cf4ec5e2191
comparison
equal deleted inserted replaced
183:a8976a008a9d 184:8c74204fd362
1 #include "seobeo/seobeo.h" 1 #include "seobeo/seobeo.h"
2 #include <strings.h> // for strcasecmp 2 #include <strings.h>
3 #include <time.h> // for time_t 3 #include <time.h>
4 4
5 static char g_folder_path[512] = "."; 5 static char g_folder_path[512] = ".";
6 6
7 char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) 7 char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size)
8 { 8 {
149 boolean is_http11 = (strstr(http_version, "1.1") != NULL); 149 boolean is_http11 = (strstr(http_version, "1.1") != NULL);
150 150
151 void *p_conn_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Connection"); 151 void *p_conn_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Connection");
152 const char *conn_header = p_conn_kv ? ((Seobeo_Request_Entry*)p_conn_kv)->value : NULL; 152 const char *conn_header = p_conn_kv ? ((Seobeo_Request_Entry*)p_conn_kv)->value : NULL;
153 153
154 if (conn_header) { 154 if (conn_header)
155 // Explicit Connection header - check for keep-alive or close 155 {
156 if (connection_header_contains(conn_header, "close")) { 156 if (connection_header_contains(conn_header, "close"))
157 should_keep_alive = FALSE; 157 should_keep_alive = FALSE;
158 } else if (connection_header_contains(conn_header, "keep-alive")) { 158 else if (connection_header_contains(conn_header, "keep-alive"))
159 should_keep_alive = use_keep_alive; 159 should_keep_alive = use_keep_alive;
160 } else { 160 else
161 // Unknown value, use version default 161 should_keep_alive = is_http11 && use_keep_alive; // Unknown value, use version default
162 should_keep_alive = is_http11 && use_keep_alive; 162 }
163 } 163 else
164 } else {
165 // No Connection header - use HTTP version defaults
166 should_keep_alive = is_http11 && use_keep_alive; 164 should_keep_alive = is_http11 && use_keep_alive;
167 }
168 165
169 void *p_method_kv = Dowa_HashMap_Get_Ptr(p_req_map, "HTTP_Method"); 166 void *p_method_kv = Dowa_HashMap_Get_Ptr(p_req_map, "HTTP_Method");
170 const char *method = p_method_kv ? ((Seobeo_Request_Entry*)p_method_kv)->value : NULL; 167 const char *method = p_method_kv ? ((Seobeo_Request_Entry*)p_method_kv)->value : NULL;
171 168
172 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path"); 169 void *p_path_kv = Dowa_HashMap_Get_Ptr(p_req_map, "Path");
267 if (strstr(file_path, ".html")) mime = "text/html; charset=utf-8"; 264 if (strstr(file_path, ".html")) mime = "text/html; charset=utf-8";
268 else if (strstr(file_path, ".css")) mime = "text/css"; 265 else if (strstr(file_path, ".css")) mime = "text/css";
269 else if (strstr(file_path, ".js")) mime = "application/javascript"; 266 else if (strstr(file_path, ".js")) mime = "application/javascript";
270 else if (strstr(file_path, ".png")) mime = "image/png"; 267 else if (strstr(file_path, ".png")) mime = "image/png";
271 else if (strstr(file_path, ".jpg") || strstr(file_path, ".jpeg")) mime = "image/jpeg"; 268 else if (strstr(file_path, ".jpg") || strstr(file_path, ".jpeg")) mime = "image/jpeg";
269 else if (strstr(file_path, ".gif")) mime = "image/gif";
270 else if (strstr(file_path, ".svg")) mime = "image/svg+xml";
271 else if (strstr(file_path, ".ico")) mime = "image/x-icon";
272 else if (strstr(file_path, ".webp")) mime = "image/webp";
272 else if (strstr(file_path, ".json")) mime = "application/json"; 273 else if (strstr(file_path, ".json")) mime = "application/json";
274 else if (strstr(file_path, ".wasm")) mime = "application/wasm";
275 else if (strstr(file_path, ".xml")) mime = "application/xml";
276 else if (strstr(file_path, ".pdf")) mime = "application/pdf";
277 else if (strstr(file_path, ".txt")) mime = "text/plain";
278 else if (strstr(file_path, ".mp4")) mime = "video/mp4";
279 else if (strstr(file_path, ".webm")) mime = "video/webm";
280 else if (strstr(file_path, ".mp3")) mime = "audio/mpeg";
281 else if (strstr(file_path, ".woff2")) mime = "font/woff2";
282 else if (strstr(file_path, ".woff")) mime = "font/woff";
283 else if (strstr(file_path, ".ttf")) mime = "font/ttf";
284 else if (strstr(file_path, ".webp")) mime = "image/webp";
285 else if (strstr(file_path, ".glb")) mime = "model/gltf-binary";
286 else if (strstr(file_path, ".gltf")) mime = "model/gltf+json";
287
273 288
274 Seobeo_Web_Header_Generate_KeepAlive(p_response_header, 289 Seobeo_Web_Header_Generate_KeepAlive(p_response_header,
275 HTTP_OK, 290 HTTP_OK,
276 mime, 291 mime,
277 body_size, should_keep_alive); 292 body_size, should_keep_alive);
787 if (route->is_param) free(route->is_param); 802 if (route->is_param) free(route->is_param);
788 } 803 }
789 Dowa_Array_Free(g_routes); 804 Dowa_Array_Free(g_routes);
790 g_routes = NULL; 805 g_routes = NULL;
791 } 806 }
792
793 // Logging functions moved to s_logging.c
794