Fix HTTP request creation and simple client example

This commit is contained in:
2025-11-23 23:27:08 +01:00
parent 3c0aecb5f0
commit f6b2c805c6
4 changed files with 41 additions and 11 deletions
+8 -2
View File
@@ -249,16 +249,22 @@ void http_request_builder_url(HTTP_RequestBuilder builder,
// Write method
HTTP_String method_str = get_method_string(method);
byte_queue_write(&conn->output, method_str.ptr, method_str.len);
byte_queue_write(&conn->output, " ", 1);
byte_queue_write(&conn->output, conn->url.path.ptr, conn->url.path.len);
// Write path
if (conn->url.path.len == 0)
byte_queue_write(&conn->output, "/", 1);
else
byte_queue_write(&conn->output, conn->url.path.ptr, conn->url.path.len);
// Write query string
HTTP_String query = conn->url.query;
if (query.len > 0) {
byte_queue_write(&conn->output, "?", 1);
byte_queue_write(&conn->output, query.ptr, query.len);
}
HTTP_String version = HTTP_STR("HTTP/1.1");
HTTP_String version = HTTP_STR(" HTTP/1.1");
byte_queue_write(&conn->output, version.ptr, version.len);
byte_queue_write(&conn->output, "\r\n", 2);
+8 -1
View File
@@ -335,7 +335,12 @@ static void socket_update(Socket *s)
continue;
}
}
AddressAndPort addr = s->addrs[s->next_addr];
AddressAndPort addr;
if (s->num_addr == 1)
addr = s->addr;
else
addr = s->addrs[s->next_addr];
int family = (addr.is_ipv4 ? AF_INET : AF_INET6);
NATIVE_SOCKET sock = socket(family, SOCK_STREAM, 0);
@@ -1011,6 +1016,8 @@ int socket_connect(SocketManager *sm, int num_targets,
s->client_secure_context = &sm->client_secure_context;
#endif
sm->num_used++;
socket_update(s);
return 0;
}