Commit Graph
40 Commits
Author SHA1 Message Date
cozis 3c0aecb5f0 Bug fixes & cleanups 2025-11-23 23:07:08 +01:00
cozis 655289e542 Merge branch 'cookie_jar' into refactoring
# Conflicts:
#	chttp.h
#	src/client.h
2025-11-23 22:36:01 +01:00
Claude 7ce2765875 Add back url_buffer as HTTP_String
Making the URL buffer allocation more explicit by storing it as
an HTTP_String. This provides both the pointer and length, making
the code clearer and more self-documenting.
2025-11-23 21:29:13 +00:00
Claude b924f0772c Remove redundant url_buffer field
Use url.scheme.ptr directly for freeing the allocated URL string,
since the scheme is always at the start of a URL. This saves 8 bytes
per connection and simplifies the code.
2025-11-23 21:28:13 +00:00
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
cozis 39d90111c9 Refactoring of the HTTP client 2025-11-23 22:11:15 +01: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
cozis fa9b0e9919 Add zero-copy interface version of http_response_builder_body 2025-11-22 23:51:43 +01:00
cozis 4ca5b67d8e Add a client example program and move examples to the examples/ folder 2025-11-22 00:13:43 +01:00
cozis eec1174047 Fix issues that caused the server to hang 2025-11-21 23:57:24 +01:00
cozis 54c02827be Bug fixes 2025-11-21 21:10:54 +01: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
cozis ccdd573e90 Add HTTPS support 2025-11-21 19:52:28 +01:00
cozis 3f76d1827e Add .gitignore and resolve simple TODOs 2025-11-21 18:39:28 +01:00
cozis 3c2ef70c66 Fix compiler errors 2025-11-21 18:30:35 +01:00
cozis aab1b8e7b8 Fix more compilation errors 2025-11-21 15:12:32 +01: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
cozis 879dc74e34 First version of the refactor 2025-11-21 12:53:03 +01:00
cozis 17ad7ad383 Add http_match_host and update 060_virtual_hosts_over_https.c 2025-10-17 12:10:35 +02:00
cozis 13c578d347 Remove router 2025-10-17 10:50:49 +02:00
cozis a4f8f3abb7 Fix missing definition of SIZEOF 2025-09-23 09:44:36 +02:00
cozis dc5376f8f3 Update chttp.c/.h 2025-09-23 09:35:36 +02:00
cozis b1021deb15 Add secure field to HTTP_Request to mark whether the underlying connection uses TLS or not 2025-09-18 09:19:38 +02:00
cozis a63e68f969 Add support for Transfer-Encoding 2025-07-28 16:32:31 +02:00
cozis 5d12070a29 Bug fix 2025-07-22 13:57:53 +02:00
cozis c134de645b Rename HTTP_ResponseHandle to HTTP_ResponseBuilder 2025-07-21 23:30:32 +02:00
cozis a67d4dea9f Bug fixes 2025-07-21 23:19:11 +02:00
cozis 73263da2c9 Fix the HTTPS build 2025-07-21 22:42:43 +02:00
cozis 51d0729aaf Fix Linux build bug 2025-07-21 21:58:26 +02:00
cozis 17b4c3d91a Improve windows support 2025-07-21 21:54:56 +02:00
cozis 58f8ace725 Add global state initialization functions 2025-07-21 21:37:02 +02:00
cozis a2912b5191 Refactoring for an improved event loop 2025-07-21 20:29:35 +02:00
cozis 5cb3977c3c Fix windows compilation errors 2025-07-21 12:06:23 +02:00
cozis acf4746611 Simplify amalgamation script 2025-07-21 02:21:33 +02:00
cozis c3bfb86707 Fix compiler errors 2025-07-20 23:53:23 +02:00
cozis 3201eac013 Fix compiler errors 2025-07-20 21:19:58 +02:00
cozis 22e9dee5dc Add docs 2025-07-20 19:24:03 +02:00
cozis dba15c946e Rename http.c/.h to chttp.c/.h and improve amalgamation formatting 2025-07-20 18:33:51 +02:00