comparison seobeo/s_web.c @ 36:84672efec192

[Zenbu] WIP fixing issues regarding to using edge only. I think there is a problem where socket closes before sending back the info.
author MrJuneJune <me@mrjunejune.com>
date Sun, 09 Nov 2025 06:25:16 -0800
parents 6c322f9c2cb9
children ea9ef388ab97
comparison
equal deleted inserted replaced
35:33b1caf051cd 36:84672efec192
56 } 56 }
57 57
58 void Seobeo_Web_HandleClientRequest(Seobeo_PHandle p_cli_handle, 58 void Seobeo_Web_HandleClientRequest(Seobeo_PHandle p_cli_handle,
59 Dowa_PHashMap p_html_cache) 59 Dowa_PHashMap p_html_cache)
60 { 60 {
61 printf("p_cli_handle: %p", p_cli_handle);
61 Dowa_PHashEntry entry = NULL; 62 Dowa_PHashEntry entry = NULL;
62 Dowa_PHashMap p_current = p_html_cache; 63 Dowa_PHashMap p_current = p_html_cache;
63 char *slash; 64 char *slash;
64 65
65 Dowa_PArena p_response_arena = Dowa_Arena_Create(1*1024*1024); 66 Dowa_PArena p_response_arena = Dowa_Arena_Create(1*1024*1024);
78 Seobeo_Handle_Queue(p_cli_handle, 79 Seobeo_Handle_Queue(p_cli_handle,
79 (const uint8*)p_response_header, 80 (const uint8*)p_response_header,
80 (uint32)strlen(p_response_header)); 81 (uint32)strlen(p_response_header));
81 Seobeo_Handle_Flush(p_cli_handle); 82 Seobeo_Handle_Flush(p_cli_handle);
82 goto clean_up; 83 goto clean_up;
83 } 84 return;
84 85 }
85 Dowa_HashMap_Print(p_req_map); 86
87 // Dowa_HashMap_Print(p_req_map);
86 88
87 // Extract method (GET, POST, etc.) 89 // Extract method (GET, POST, etc.)
88 const char *method = (const char*)Dowa_HashMap_Get(p_req_map, "HTTP_Method"); 90 const char *method = (const char*)Dowa_HashMap_Get(p_req_map, "HTTP_Method");
89 if (!method) 91 if (!method)
90 { 92 {
247 Seobeo_Handle_Flush(p_cli_handle); 249 Seobeo_Handle_Flush(p_cli_handle);
248 } 250 }
249 goto clean_up; 251 goto clean_up;
250 252
251 clean_up: 253 clean_up:
252 if (p_cli_handle) 254 printf("clean up\n\n");
253 Seobeo_Handle_Destroy(p_cli_handle); 255 return;
254 if (p_response_arena) 256 // if (p_cli_handle)
255 Dowa_Arena_Destroy(p_response_arena); 257 // Seobeo_Handle_Destroy(p_cli_handle);
258 // if (p_response_arena)
259 // Dowa_Arena_Destroy(p_response_arena);
256 } 260 }
257 261
258 262
259 int Seobeo_Web_Header_Parse(Seobeo_PHandle p_handle, Dowa_PHashMap map) 263 int Seobeo_Web_Header_Parse(Seobeo_PHandle p_handle, Dowa_PHashMap map)
260 { 264 {
398 memcpy(val, val_start, value_len); 402 memcpy(val, val_start, value_len);
399 val[value_len] = '\0'; 403 val[value_len] = '\0';
400 404
401 Dowa_HashMap_Push_Value_With_Type(map, key, val, value_len + 1, DOWA_HASH_MAP_TYPE_STRING); 405 Dowa_HashMap_Push_Value_With_Type(map, key, val, value_len + 1, DOWA_HASH_MAP_TYPE_STRING);
402 406
403 printf("Capacity: %d, Length: %d ", (int)map->p_arena->capacity, (int)map->p_arena->offset); 407 // printf("Capacity: %d, Length: %d ", (int)map->p_arena->capacity, (int)map->p_arena->offset);
404 printf("value_len: %d, key: %s value %s position: %d\n\n", (int)value_len + 1, key, val, Dowa_HashMap_Get_Position(map, key)); 408 // printf("value_len: %d, key: %s value %s position: %d\n\n", (int)value_len + 1, key, val, Dowa_HashMap_Get_Position(map, key));
405 printf("Method: %s Position: %d Pointer %p\n\n", Dowa_HashMap_Get(map, "HTTP_Method"), Dowa_HashMap_Get_Position(map, "HTTP_Method"), map); 409 // printf("Method: %s Position: %d Pointer %p\n\n", Dowa_HashMap_Get(map, "HTTP_Method"), Dowa_HashMap_Get_Position(map, "HTTP_Method"), map);
406 410
407 free(key); 411 Dowa_Free(key);
408 free(val); 412 Dowa_Free(val);
409 } 413 }
410 414
411 line = next + 2; 415 line = next + 2;
412 } 416 }
413 Seobeo_Handle_Consume(p_handle, (uint32)hdr_len); 417 Seobeo_Handle_Consume(p_handle, (uint32)hdr_len);
428 char *body = malloc(body_len + 1); 432 char *body = malloc(body_len + 1);
429 memcpy(body, p_handle->read_buffer, body_len); 433 memcpy(body, p_handle->read_buffer, body_len);
430 body[body_len] = '\0'; 434 body[body_len] = '\0';
431 435
432 Dowa_HashMap_Push_Value(map, "Body", body, body_len + 1); 436 Dowa_HashMap_Push_Value(map, "Body", body, body_len + 1);
433 free(body); 437 Dowa_Free(body);
434 438
435 Seobeo_Handle_Consume(p_handle, (uint32)body_len); 439 Seobeo_Handle_Consume(p_handle, (uint32)body_len);
436 } 440 }
437 441
438 return 0; // success; map now holds Method, Path, Version, headers, and optional Body 442 return 0; // success; map now holds Method, Path, Version, headers, and optional Body
481 sa.sa_flags = SA_RESTART; 485 sa.sa_flags = SA_RESTART;
482 sigaction(SIGCHLD, &sa, NULL); 486 sigaction(SIGCHLD, &sa, NULL);
483 487
484 while (1) 488 while (1)
485 { 489 {
486 Seobeo_PHandle cli = 490 Seobeo_PHandle p_cli_handle =
487 Seobeo_Stream_Handle_Server_Accept(p_server_handle); 491 Seobeo_Stream_Handle_Server_Accept(p_server_handle);
488 if (!cli) continue; 492 if (!p_cli_handle) continue;
489 493
490 if (fork() == 0) 494 if (fork() == 0)
491 { 495 {
492 Seobeo_Web_HandleClientRequest(cli, 496 Seobeo_Web_HandleClientRequest(p_cli_handle,
493 p_html_cache); 497 p_html_cache);
494 _exit(0); 498 _exit(0);
495 } 499 }
496 } 500 }
497 } 501 }
498 502
499 if (mode == SEOBEO_MODE_EDGE) 503 if (mode == SEOBEO_MODE_EDGE)
500 { 504 {
501 printf("EDGE MODE\n"); 505 printf("EDGE MODE\n");
502 Seobeo_Web_Edge(p_server_handle, thread_count, p_html_cache); 506 Seobeo_Web_Edge_2(p_server_handle, p_html_cache);
507 // Seobeo_Web_Edge(p_server_handle, thread_count, p_html_cache);
503 } 508 }
504 509
505 return -1; 510 return -1;
506 } 511 }
507 512