Skip to content

Commit

Permalink
ad ca info version check
Browse files Browse the repository at this point in the history
  • Loading branch information
jiacai2050 committed May 12, 2024
1 parent 2543094 commit bfff9ce
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 17 deletions.
3 changes: 1 addition & 2 deletions build.zig
Original file line number Diff line number Diff line change
Expand Up @@ -74,15 +74,14 @@ fn addExample(
.optimize = optimize,
.link_libc = true,
});

b.installArtifact(exe);

exe.root_module.addImport(MODULE_NAME, curl_module);
if (libcurl) |lib| {
exe.linkLibrary(lib);
} else {
exe.linkSystemLibrary("curl");
}
exe.linkLibC();

const run_step = b.step(
"run-" ++ name,
Expand Down
20 changes: 5 additions & 15 deletions examples/multi.zig
Original file line number Diff line number Diff line change
Expand Up @@ -10,28 +10,18 @@ const c = curl.libcurl;
pub fn main() !void {
const allocator = std.heap.page_allocator;

const ca_bundle = try curl.allocCABundle(allocator);
defer ca_bundle.deinit();
const easy = try Easy.init(allocator, .{
.ca_bundle = ca_bundle,
});
try easy.setUrl("http://httpbin.org/headers");
defer easy.deinit();

const easy2 = try Easy.init(allocator, .{
.ca_bundle = ca_bundle,
});
try easy2.setUrl("http://httpbin.org/ip");
defer easy2.deinit();

const multi = try Multi.init();
defer multi.deinit();

const easy = try Easy.init(allocator, .{});
try easy.setUrl("http://httpbin.org/headers");
try multi.addHandle(easy);

const easy2 = try Easy.init(allocator, .{});
try easy2.setUrl("http://httpbin.org/ip");
try multi.addHandle(easy2);

var running = true;

while (running) {
const transfer = try multi.perform();
running = transfer != 0;
Expand Down
4 changes: 4 additions & 0 deletions src/Easy.zig
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ pub fn bufferWriteCallback(ptr: [*c]c_char, size: c_uint, nmemb: c_uint, user_da

pub fn setCommonOpts(self: Self) !void {
if (self.ca_bundle) |bundle| {
// https://curl.se/libcurl/c/CURLOPT_CAINFO_BLOB.html
if (!c.CURL_AT_LEAST_VERSION(7, 81, 0)) {
return error.NoCaInfoBlobSupport;
}
const blob = c.curl_blob{
.data = @constCast(bundle.items.ptr),
.len = bundle.items.len,
Expand Down

0 comments on commit bfff9ce

Please sign in to comment.