Mercurial
diff seobeo/s_web.c @ 119:c39582f937e5
[Seobeo Client] Added client side logic which will be used for all my other calls instead of curl.
| author | June Park <parkjune1995@gmail.com> |
|---|---|
| date | Wed, 07 Jan 2026 16:05:57 -0800 |
| parents | 99c4530e4629 |
| children | 7b1719fa918c |
line wrap: on
line diff
--- a/seobeo/s_web.c Wed Jan 07 13:24:38 2026 -0800 +++ b/seobeo/s_web.c Wed Jan 07 16:05:57 2026 -0800 @@ -2,33 +2,6 @@ static char g_folder_path[512] = "."; -int Seobeo_Web_GenerateRequestHeader( - void *buffer, const char *host, - const char *path) -{ - return sprintf( - buffer, - "GET %s HTTP/1.1\r\n" - "Host: %s\r\n" - "Connection: close\r\n" - "accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.7\r\n" - "accept-language: en-GB,en;q=0.9,en-US;q=0.8,ko;q=0.7\r\n" - "if-modified-since: Sat, 02 Aug 2025 22:51:58 GMT\r\n" - "if-none-match: W/\"688e968e-5700\"\r\n" - "priority: u=0, i\r\n" - "sec-ch-ua: \"Chromium\";v=\"140\", \"Not=A?Brand\";v=\"24\", \"Google Chrome\";v=\"140\"\r\n" - "sec-ch-ua-mobile: 0\r\n" - "sec-ch-ua-platform: \"macOS\"\r\n" - "sec-fetch-dest: document\r\n" - "sec-fetch-mode: navigate\r\n" - "sec-fetch-site: none\r\n" - "sec-fetch-user: 1\r\n" - "upgrade-insecure-requests: 1\r\n" - "\r\n", - path, host - ); -} - char* Seobeo_Web_LoadFile(const char *file_path, size_t *p_file_size) { char full_path[1024]; @@ -551,73 +524,6 @@ return -1; } -int Seobeo_Web_Client_Get(const char *host, - const char *port, - const char *path) -{ - Seobeo_Handle *h = Seobeo_Stream_Handle_Client_Create(host, port, TRUE); - if (!h || h->socket < 0) - { - if (h) - Seobeo_Handle_Destroy(h); - return -1; - } - - Dowa_Arena *p_request_arena = Dowa_Arena_Create(1 * 1024 * 1024); - if (!p_request_arena) { perror("Dowa_Arena_Create"); return -1; } - - void *p_request_header = Dowa_Arena_Allocate(p_request_arena, 4096); - if (!p_request_header) { perror("Dowa_Arena_Allocate"); return -1; } - - int request_len = Seobeo_Web_GenerateRequestHeader(p_request_header, host, path); - - Seobeo_Handle_Queue(h, (uint8 *)p_request_header, (uint32)request_len); - if (Seobeo_Handle_Flush(h) < 0) - { - perror("Seobeo_Handle_Flush"); - Seobeo_Handle_Destroy(h); - return -1; - } - - size_t cap = 1024*8, used = 0; - char *p_request_body = Dowa_Arena_Allocate(p_request_arena, cap); - if (!p_request_body) { Seobeo_Handle_Destroy(h); return -1; } - - while (1) - { - int n = Seobeo_Handle_Read(h); - Seobeo_Log(SEOBEO_DEBUG, "Received size: %d bytes\n", n); - if (n > 0) - { - // TODO: Maybe directly use arena inside of the struct? idk if that is useful or not... - memcpy(p_request_body + used, h->read_buffer, h->read_buffer_len); - used += h->read_buffer_len; - Seobeo_Handle_Consume(h, (uint32)h->read_buffer_len); - } - else if (n == 0) - { - // Wait - continue; - } - else if (n == -2) - { - Seobeo_Log(SEOBEO_DEBUG, "Connection closed by client\n"); - break; - } - else - { - Dowa_Arena_Free(p_request_arena); - Seobeo_Handle_Destroy(h); - return -1; - } - } - - Seobeo_Log(SEOBEO_DEBUG, "Request body: %s\n", p_request_body); - Dowa_Arena_Free(p_request_arena); - Seobeo_Handle_Destroy(h); - return 0; -} - /* Router logic */ struct Seobeo_Route_Struct { char *method; // "GET", "POST", "PUT", "DELETE"