Release v0.2.6
Pre-releaseZAP Release v0.2.6
Updates
TLS / HTTPS / openssl build change!!!
Previously, zap required -Dopenssl=true
to build openssl support. Turns out, for projects using zap, it's insanely hard if not impossible to pass the user provided option openssl=true
down to the zap dependency.
As a workaround, I changed the build so that it now expects an environment variable ZAP_USE_OPENSSL
be set to true
.
So, to build the https example, run:
ZAP_USE_OPENSSL=true zig build run-https
The Example
Create the certificate and key file:
$ openssl req -x509 -nodes -days 365 -sha256 -newkey rsa:2048 -keyout mykey.pem -out mycert.pem
Build / run the example
$ ZAP_USE_OPENSSL=true zig build https
$ ZAP_USE_OPENSSL=true zig build -Dopenssl=true run-https
Issue an HTTPS request:
$ curl -v -k https://localhost:4443/build.zig
Using openssl in your code is super simple:
const tls = zap.fio_tls_new(
"localhost:4443",
CERT_FILE,
KEY_FILE,
null, // key file is not password-protected
);
defer tls.deinit();
That tls
data is then passed to the SimpleHttpListener
:
var listener = zap.SimpleHttpListener.init(.{
.port = 4443,
.on_request = on_request_verbose,
.log = true,
.max_clients = 100000,
.tls = tls, // <----- h e r e
});
try listener.listen();
Using it
To use in your own projects, put this dependency into your build.zig.zon
:
// zap v0.2.6
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.6.tar.gz",
.hash = "1220140b2cdb01223ebd9c8d9f978df8a4b5c50b75f2170ed6af4cb477374511b8eb",
}
Here is a complete build.zig.zon
example:
.{
.name = "My example project",
.version = "0.0.1",
.dependencies = .{
// zap v0.2.6
.zap = .{
.url = "https://github.com/zigzap/zap/archive/refs/tags/v0.2.6.tar.gz",
.hash = "1220140b2cdb01223ebd9c8d9f978df8a4b5c50b75f2170ed6af4cb477374511b8eb",
}
}
}
Then, in your build.zig
's build
function, add the following before exe.install()
:
const zap = b.dependency("zap", .{
.target = target,
.optimize = optimize,
});
exe.addModule("zap", zap.module("zap"));
exe.linkLibrary(zap.artifact("facil.io"));