Commit Graph
7 Commits
Author SHA1 Message Date
Claude e87fa490df Fix dangling pointer bug in URL storage
The previous implementation stored parsed_url which contained pointers
into the user's string literal that could be invalidated. This fix:

1. Allocates a copy of the URL string (url_buffer)
2. Parses the copy so all pointers reference owned memory
3. Removes redundant domain and path fields from HTTP_ClientConn
4. Updates save_cookies to use url.authority.host.text and url.path
5. Updates cleanup code to free url_buffer instead of domain.ptr

This ensures the URL and all its components remain valid for the
lifetime of the connection.
2025-11-23 21:26:59 +00:00
Claude 737d81f270 Fix compilation errors in cookie_jar branch
This commit fixes multiple compilation errors introduced by the refactoring:

1. Added missing http_client_conn_free() helper function
2. Fixed cookie_jar reference (cookie_jar->count to client->cookie_jar.count)
3. Restored missing HTTP_ClientConn fields: handle, client, and url
4. Fixed undefined 'conn' variable in http_client_get_builder (changed to 'i')
5. Fixed incorrect field reference (entry.domain.len to domain.len)
6. Added missing closing parenthesis in should_send_cookie
7. Removed duplicate 'path' variable declaration
8. Fixed cookie jar access to use builder.client instead of conn->client
9. Fixed byte_queue_write calls to use .ptr and .len instead of HTTP_String structs
10. Fixed missing -> operators in url_to_connect_target
11. Fixed undefined 'url' variable by using conn->url
12. Fixed headers[i].value to set_cookie.value in save_one_cookie
13. Fixed typo: antry to entry
14. Fixed save_one_cookie parameter type (headers[i] instead of headers[i].value)
15. Fixed print_bytes calls to create HTTP_String structs
16. Added logic to store socket handle when connection is established
17. Updated http_client_get_builder signature to return HTTP_RequestBuilder
18. Updated simple_client.c example to match new API
2025-11-23 21:18:09 +00:00
Claude 6cb5bdacd2 Complete Set-Cookie header parser implementation
Implemented missing functionality in the Set-Cookie parser:

1. Completed is_cookie_octet() function to properly validate cookie characters
   according to RFC 6265 (excludes CTLs, whitespace, DQUOTE, comma, semicolon, backslash)

2. Fixed http_parse_set_cookie() return type from void to int to properly
   report parsing errors

3. Implemented Path attribute parsing to extract cookie path restrictions

4. Fixed HttpOnly attribute bug where it was incorrectly set to false instead of true

5. Added path field to HTTP_SetCookie struct with have_path flag

6. Added missing return 0 statement for successful parsing

7. Exported Set-Cookie parser types and function to public API:
   - HTTP_WeekDay, HTTP_Month, HTTP_Date enums/struct
   - HTTP_SetCookie struct
   - http_parse_set_cookie() function

All changes follow RFC 6265 specification for Set-Cookie header parsing.
2025-11-23 15:59:31 +00:00
Claudeandcozis 51d3f84715 Address code review feedback for HTTP client and server
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.
2025-11-21 20:37:18 +01:00
Claude 9868ae2e33 Implement HTTP client in consistent style with server.c
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
2025-11-21 19:17:18 +00:00
Claude 2d407b63c2 Fix TODOs unrelated to HTTP client
- Add documentation comments for print_bytes() and HTTP_UNPACK macro in src/basic.h
- Improve error handling in src/socket.c: add checks for ioctlsocket, socket creation,
  and connection failures; implement socket_manager_wakeup with proper signaling;
  consume wakeup signals; add memory cleanup for registered names
- Add header validation in src/server.c to prevent HTTP response splitting attacks
- Enhance HTTP parsing in src/parse.c: support percent-encoded characters in userinfo,
  expand HTTP methods without request bodies, add response body detection logic,
  improve cookie parsing comments
- Document unused 'ad' parameter in src/secure_context.c SNI callback
2025-11-21 19:07:51 +00:00
Claude 93ccb5d6a1 Fix minor refactoring errors
Minor fixes:
- Add missing includes in src/includes.h (stdbool, string, stdlib, poll, fcntl, errno, netdb, arpa/inet, netinet/in)
- Fix empty Mutex struct in src/thread.h
- Fix String -> HTTP_String typos in 5 source files
- Fix server_secure_context_add_certificate missing key_file parameter

Non-trivial issues remain (see PR description for details)
2025-11-21 12:15:11 +00:00