From 960d54a43394e5ad923d66aeab6252247d040138 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=81d=C3=A1m=20Kov=C3=A1cs?= Date: Fri, 28 Mar 2025 09:11:36 +0100 Subject: [PATCH] wip: Http client --- src/main.zig | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/src/main.zig b/src/main.zig index 238e574..10c15b4 100644 --- a/src/main.zig +++ b/src/main.zig @@ -37,6 +37,33 @@ export fn main() c_int { // } // _ = p.printf("Hello world\n"); + std.options.page_size_max = 4096; + // Create a general purpose allocator + var gpa = std.heap.GeneralPurposeAllocator(.{}){}; + defer _ = gpa.deinit(); + + // Create a HTTP client + var client = std.http.Client{ .allocator = gpa.allocator() }; + defer client.deinit(); + + // Allocate a buffer for server headers + var buf: [4096]u8 = undefined; + + // Start the HTTP request + const uri = try std.Uri.parse("https://www.google.com?q=zig"); + var req = try client.open(.GET, uri, .{ .server_header_buffer = &buf }); + defer req.deinit(); + + // Send the HTTP request headers + try req.send(); + // Finish the body of a request + try req.finish(); + + // Waits for a response from the server and parses any headers that are sent + try req.wait(); + + std.debug.print("status={d}\n", .{req.response.status}); + while (true) { while (p.gpio_get(BUTTON_PIN)) { p.cyw43_arch_gpio_put(p.CYW43_WL_GPIO_LED_PIN, true);