Mercurial
comparison 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 |
comparison
equal
deleted
inserted
replaced
| 151:c033667da5f9 | 173:827c6ac504cd |
|---|---|
| 229 if (!p_resp) | 229 if (!p_resp) |
| 230 return NULL; | 230 return NULL; |
| 231 | 231 |
| 232 memset(p_resp, 0, sizeof(Seobeo_Client_Response)); | 232 memset(p_resp, 0, sizeof(Seobeo_Client_Response)); |
| 233 | 233 |
| 234 p_resp->p_arena = Dowa_Arena_Create(1024 * 1024); | 234 p_resp->p_arena = Dowa_Arena_Create(1024 * 1024 * 5); // 5 MB |
| 235 if (!p_resp->p_arena) | 235 if (!p_resp->p_arena) |
| 236 { | 236 { |
| 237 free(p_resp); | 237 free(p_resp); |
| 238 return NULL; | 238 return NULL; |
| 239 } | 239 } |
| 240 | 240 |
| 241 while (1) | 241 while (TRUE) |
| 242 { | 242 { |
| 243 int r = Seobeo_Handle_Read(p_handle); | 243 int r = Seobeo_Handle_Read(p_handle); |
| 244 if (r < 0) | 244 if (r < 0) |
| 245 return p_resp; | 245 return p_resp; |
| 246 if (r == -2) | 246 if (r == -2) |
| 389 p_resp->body_length = total_read; | 389 p_resp->body_length = total_read; |
| 390 } | 390 } |
| 391 } | 391 } |
| 392 else | 392 else |
| 393 { | 393 { |
| 394 size_t cap = 1024 * 8; | 394 size_t cap = 1024 * 1024 * 3; |
| 395 size_t used = 0; | 395 size_t used = 0; |
| 396 char *body = download_path ? NULL : Dowa_Arena_Allocate(p_resp->p_arena, cap); | 396 char *body = download_path ? NULL : Dowa_Arena_Allocate(p_resp->p_arena, cap); |
| 397 | 397 |
| 398 while (1) | 398 while (1) |
| 399 { | 399 { |
| 412 Seobeo_Log(SEOBEO_WARNING, "Response body too large, truncating...\n"); | 412 Seobeo_Log(SEOBEO_WARNING, "Response body too large, truncating...\n"); |
| 413 break; | 413 break; |
| 414 } | 414 } |
| 415 memcpy(body + used, p_handle->read_buffer, p_handle->read_buffer_len); | 415 memcpy(body + used, p_handle->read_buffer, p_handle->read_buffer_len); |
| 416 used += p_handle->read_buffer_len; | 416 used += p_handle->read_buffer_len; |
| 417 Seobeo_Log(SEOBEO_DEBUG, "Copied %zu bytes, total %zu/%zu\n", used, used + p_handle->read_buffer_len, body_len); | |
| 417 } | 418 } |
| 418 Seobeo_Handle_Consume(p_handle, (uint32)p_handle->read_buffer_len); | 419 Seobeo_Handle_Consume(p_handle, (uint32)p_handle->read_buffer_len); |
| 419 } | 420 } |
| 420 else if (n == -2) | 421 else if (n == -2) |
| 421 break; | 422 break; |
| 538 return; | 539 return; |
| 539 | 540 |
| 540 if (p_req->p_arena) | 541 if (p_req->p_arena) |
| 541 Dowa_Arena_Free(p_req->p_arena); | 542 Dowa_Arena_Free(p_req->p_arena); |
| 542 | 543 |
| 543 if (p_req->headers_map) | 544 // Note: headers_map and headers_array are allocated using arena functions |
| 544 Dowa_HashMap_Free(p_req->headers_map); | 545 // (Dowa_HashMap_Push_Arena, Dowa_Array_Push_Arena), so they are freed |
| 545 | 546 // when the arena is freed above. Do not call Dowa_HashMap_Free or |
| 546 if (p_req->headers_array) | 547 // Dowa_Array_Free on them. |
| 547 Dowa_Array_Free(p_req->headers_array); | |
| 548 | 548 |
| 549 free(p_req); | 549 free(p_req); |
| 550 } | 550 } |
| 551 | 551 |
| 552 void Seobeo_Client_Response_Destroy(Seobeo_Client_Response *p_resp) | 552 void Seobeo_Client_Response_Destroy(Seobeo_Client_Response *p_resp) |
| 555 return; | 555 return; |
| 556 | 556 |
| 557 if (p_resp->p_arena) | 557 if (p_resp->p_arena) |
| 558 Dowa_Arena_Free(p_resp->p_arena); | 558 Dowa_Arena_Free(p_resp->p_arena); |
| 559 | 559 |
| 560 if (p_resp->headers) | 560 // Note: headers are allocated using Dowa_HashMap_Push_Arena, so they are |
| 561 Dowa_HashMap_Free(p_resp->headers); | 561 // freed when the arena is freed above. Do not call Dowa_HashMap_Free. |
| 562 | 562 |
| 563 free(p_resp); | 563 free(p_resp); |
| 564 } | 564 } |