diff seobeo/s_http_client.c @ 173:827c6ac504cd hg-web

Merged in default here.
author MrJuneJune <me@mrjunejune.com>
date Mon, 19 Jan 2026 18:59:10 -0800
parents f3084bca7317
children 71ad34a8bc9a
line wrap: on
line diff
--- a/seobeo/s_http_client.c	Sat Jan 10 13:35:09 2026 -0800
+++ b/seobeo/s_http_client.c	Mon Jan 19 18:59:10 2026 -0800
@@ -231,14 +231,14 @@
 
   memset(p_resp, 0, sizeof(Seobeo_Client_Response));
 
-  p_resp->p_arena = Dowa_Arena_Create(1024 * 1024);
+  p_resp->p_arena = Dowa_Arena_Create(1024 * 1024 * 5); // 5 MB 
   if (!p_resp->p_arena)
   {
     free(p_resp);
     return NULL;
   }
 
-  while (1)
+  while (TRUE)
   {
     int r = Seobeo_Handle_Read(p_handle);
     if (r < 0)
@@ -391,7 +391,7 @@
   }
   else
   {
-    size_t cap = 1024 * 8;
+    size_t cap = 1024 * 1024 * 3;
     size_t used = 0;
     char *body = download_path ? NULL : Dowa_Arena_Allocate(p_resp->p_arena, cap);
 
@@ -414,6 +414,7 @@
           }
           memcpy(body + used, p_handle->read_buffer, p_handle->read_buffer_len);
           used += p_handle->read_buffer_len;
+          Seobeo_Log(SEOBEO_DEBUG, "Copied %zu bytes, total %zu/%zu\n", used, used + p_handle->read_buffer_len, body_len);
         }
         Seobeo_Handle_Consume(p_handle, (uint32)p_handle->read_buffer_len);
       }
@@ -540,11 +541,10 @@
   if (p_req->p_arena)
     Dowa_Arena_Free(p_req->p_arena);
 
-  if (p_req->headers_map)
-    Dowa_HashMap_Free(p_req->headers_map);
-
-  if (p_req->headers_array)
-    Dowa_Array_Free(p_req->headers_array);
+  // Note: headers_map and headers_array are allocated using arena functions
+  // (Dowa_HashMap_Push_Arena, Dowa_Array_Push_Arena), so they are freed
+  // when the arena is freed above. Do not call Dowa_HashMap_Free or
+  // Dowa_Array_Free on them.
 
   free(p_req);
 }
@@ -557,8 +557,8 @@
   if (p_resp->p_arena)
     Dowa_Arena_Free(p_resp->p_arena);
 
-  if (p_resp->headers)
-    Dowa_HashMap_Free(p_resp->headers);
+  // Note: headers are allocated using Dowa_HashMap_Push_Arena, so they are
+  // freed when the arena is freed above. Do not call Dowa_HashMap_Free.
 
   free(p_resp);
 }