From a7448525ed9eef827475b91a1f87af766ea3b15f Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 10 Mar 2026 14:09:31 -0700 Subject: [PATCH] api.finnhub.io supports TLS 1.3 - curl fallback removed --- src/net/http.zig | 71 +-------------------------------------- src/providers/finnhub.zig | 2 +- 2 files changed, 2 insertions(+), 71 deletions(-) diff --git a/src/net/http.zig b/src/net/http.zig index 2c7f346..b9664c3 100644 --- a/src/net/http.zig +++ b/src/net/http.zig @@ -70,13 +70,8 @@ pub const Client = struct { .payload = body, .extra_headers = extra_headers, .response_writer = &aw.writer, - }) catch |err| { + }) catch { aw.deinit(); - // TLS 1.2-only hosts (e.g., finnhub.io) fail with Zig's TLS 1.3-only client. - // Fall back to system curl for these cases. - if (err == error.TlsInitializationFailed) { - return curlRequest(self.allocator, method, url, body, extra_headers); - } return HttpError.RequestFailed; }; @@ -104,70 +99,6 @@ pub const Client = struct { } }; -/// Fallback HTTP request using system curl for TLS 1.2 hosts. -fn curlRequest( - allocator: std.mem.Allocator, - method: std.http.Method, - url: []const u8, - body: ?[]const u8, - extra_headers: []const std.http.Header, -) HttpError!Response { - var argv: std.ArrayList([]const u8) = .empty; - defer argv.deinit(allocator); - - // Heap-allocated strings that need freeing after Child.run - var to_free: std.ArrayList([]const u8) = .empty; - defer { - for (to_free.items) |s| allocator.free(s); - to_free.deinit(allocator); - } - - argv.appendSlice(allocator, &.{ "curl", "-sS", "-f", "-L", "--max-time", "30" }) catch - return HttpError.OutOfMemory; - - if (method != .GET) { - argv.appendSlice(allocator, &.{ "-X", @tagName(method) }) catch - return HttpError.OutOfMemory; - } - - for (extra_headers) |hdr| { - const val = std.fmt.allocPrint(allocator, "{s}: {s}", .{ hdr.name, hdr.value }) catch - return HttpError.OutOfMemory; - to_free.append(allocator, val) catch return HttpError.OutOfMemory; - argv.appendSlice(allocator, &.{ "-H", val }) catch return HttpError.OutOfMemory; - } - - if (body) |b| { - argv.appendSlice(allocator, &.{ "-d", b }) catch return HttpError.OutOfMemory; - } - - argv.append(allocator, url) catch return HttpError.OutOfMemory; - - const result = std.process.Child.run(.{ - .allocator = allocator, - .argv = argv.items, - .max_output_bytes = 10 * 1024 * 1024, - }) catch return HttpError.RequestFailed; - - allocator.free(result.stderr); - - const success = switch (result.term) { - .Exited => |code| code == 0, - else => false, - }; - - if (!success) { - allocator.free(result.stdout); - return HttpError.RequestFailed; - } - - return .{ - .status = .ok, - .body = result.stdout, - .allocator = allocator, - }; -} - /// Build a URL with query parameters. pub fn buildUrl( allocator: std.mem.Allocator, diff --git a/src/providers/finnhub.zig b/src/providers/finnhub.zig index 6e56a2f..da15d73 100644 --- a/src/providers/finnhub.zig +++ b/src/providers/finnhub.zig @@ -16,7 +16,7 @@ const json_utils = @import("json_utils.zig"); const optFloat = json_utils.optFloat; const jsonStr = json_utils.jsonStr; -const base_url = "https://finnhub.io/api/v1"; +const base_url = "https://api.finnhub.io/api/v1"; pub const Finnhub = struct { api_key: []const u8,