Based on code review feedback:
Client improvements:
- Remove redundant capacity check in http_client_get_builder
(already verified num_conns < capacity)
- Fix generation counter - no longer reset to zero when allocating
connections, only incremented on request send
- Add HTTP_Method parameter to http_request_builder_url instead
of hardcoding GET method
- Free connection resources when http_request_builder_send fails
(invalid host mode or socket_connect failure)
Server bug fix:
- Fix ready queue indexing in http_server_next_request
Changed: &server->conns[server->ready_head]
To: &server->conns[server->ready[server->ready_head]]
This bug would have caused incorrect connection retrieval
All changes maintain consistency with the codebase style and
improve robustness of error handling.
Refactored HTTP client implementation to follow the same coding
patterns and style as server.c:
- Added static helper functions (http_client_conn_init,
http_client_conn_free, check_response_buffer, request_builder_to_conn)
- Implemented buffer limit setters (http_client_set_input_limit,
http_client_set_output_limit)
- Fully implemented request builder API (url, header, body, send)
- Implemented event processing with state machine approach
- Added connection reuse support via http_free_response
- Used consistent naming, formatting, and error handling patterns
- Renamed builder_to_conn to request_builder_to_conn to avoid
symbol conflicts with server.c during amalgamation
The implementation follows the same architecture as the server:
- Connection state machine for managing request/response lifecycle
- ByteQueue for input/output buffering
- Ready queue for completed responses
- Generation counters for builder validation
- Socket manager integration for async I/O