mirror of
https://github.com/zigzap/zap.git
synced 2025-10-20 15:14:08 +00:00
0.12.0 ready
This commit is contained in:
parent
e85a24c006
commit
82323f835e
29 changed files with 180 additions and 151 deletions
11
README.md
11
README.md
|
@ -30,17 +30,6 @@ Exactly the goals I set out to achieve!
|
|||
|
||||
## Most FAQ:
|
||||
|
||||
- Q: **Zap doesn't build with Zig master?**
|
||||
- A: <mark>**Zap depends on the latest stable release of Zig**, which is **ZIG
|
||||
V0.11**</mark> at the moment. Contributers provide forks with v0.12/master
|
||||
branches which I may integrate soon-ish.
|
||||
- A2: Going "stable" is a deliberate decision. Zap is designed to be
|
||||
depended on by professional, production-grade servers, not just toy
|
||||
projects or Zig/Zap enthusiasts. Having zap not break with frequent
|
||||
changes of zig master, is a feature. We experienced the catch-up game when
|
||||
Zig 0.11 was in development and decided that it might be a big turn-off,
|
||||
especially for professional projects.
|
||||
- A3: We're going to add a `zig-master` branch soon. (Probably early 2024).
|
||||
- Q: **Does ZAP work on Windows?**
|
||||
- A: No. This is due to the underlying facil.io C library. Future versions of
|
||||
facil.io might support Windows but there is no timeline yet. Your best options
|
||||
|
|
|
@ -10,7 +10,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
const use_openssl = b.option(bool, "openssl", "Use system-installed openssl for TLS support in zap") orelse false;
|
||||
|
||||
// create a module to be used internally.
|
||||
var zap_module = b.createModule(.{
|
||||
const zap_module = b.createModule(.{
|
||||
.source_file = .{ .path = "src/zap.zig" },
|
||||
});
|
||||
|
||||
|
@ -84,8 +84,10 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
// install the artifact - depending on the "example"
|
||||
const example_build_step = b.addInstallArtifact(example, .{});
|
||||
example_step.dependOn(&example_build_step.step);
|
||||
if (!std.mem.eql(u8, ex_name, "https")) {
|
||||
all_step.dependOn(&example_build_step.step);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// TOOLS & TESTING
|
||||
|
@ -185,7 +187,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
//
|
||||
// pkghash
|
||||
//
|
||||
var pkghash_exe = b.addExecutable(.{
|
||||
const pkghash_exe = b.addExecutable(.{
|
||||
.name = "pkghash",
|
||||
.root_source_file = .{ .path = "./tools/pkghash.zig" },
|
||||
.target = target,
|
||||
|
@ -199,7 +201,7 @@ pub fn build(b: *std.build.Builder) !void {
|
|||
//
|
||||
// announceybot
|
||||
//
|
||||
var announceybot_exe = b.addExecutable(.{
|
||||
const announceybot_exe = b.addExecutable(.{
|
||||
.name = "announceybot",
|
||||
.root_source_file = .{ .path = "./tools/announceybot.zig" },
|
||||
.target = target,
|
||||
|
|
|
@ -1 +1,10 @@
|
|||
.{ .name = "zap", .version = "0.2.0" }
|
||||
.{
|
||||
.name = "zap",
|
||||
.version = "0.2.2",
|
||||
.paths = .{
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
"src",
|
||||
"facil.io",
|
||||
},
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ const Handler = struct {
|
|||
// check for query params (for ?terminate=true)
|
||||
r.parseQuery();
|
||||
|
||||
var param_count = r.getParamCount();
|
||||
const param_count = r.getParamCount();
|
||||
std.log.info("param_count: {}", .{param_count});
|
||||
|
||||
// iterate over all params
|
||||
|
@ -87,7 +87,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
Handler.alloc = allocator;
|
||||
|
||||
|
|
|
@ -11,11 +11,11 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
|||
var http_client: std.http.Client = .{ .allocator = a };
|
||||
defer http_client.deinit();
|
||||
|
||||
var req = try http_client.request(.GET, uri, h, .{});
|
||||
var req = try http_client.open(.GET, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
try req.headers.append("cookie", "ZIG_ZAP=awesome");
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
try req.wait();
|
||||
}
|
||||
|
||||
|
@ -28,7 +28,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const Handler = struct {
|
||||
var alloc: std.mem.Allocator = undefined;
|
||||
|
@ -39,7 +39,7 @@ pub fn main() !void {
|
|||
|
||||
r.parseCookies(false);
|
||||
|
||||
var cookie_count = r.getCookiesCount();
|
||||
const cookie_count = r.getCookiesCount();
|
||||
std.log.info("cookie_count: {}", .{cookie_count});
|
||||
|
||||
// iterate over all cookies as strings
|
||||
|
|
|
@ -82,7 +82,7 @@ fn listUsers(self: *Self, r: zap.SimpleRequest) void {
|
|||
fn postUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
|
||||
const self = @fieldParentPtr(Self, "endpoint", e);
|
||||
if (r.body) |body| {
|
||||
var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||
if (maybe_user) |u| {
|
||||
defer u.deinit();
|
||||
if (self.users.addByName(u.value.first_name, u.value.last_name)) |id| {
|
||||
|
@ -104,7 +104,7 @@ fn putUser(e: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
|
|||
if (self.userIdFromPath(path)) |id| {
|
||||
if (self.users.get(id)) |_| {
|
||||
if (r.body) |body| {
|
||||
var maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||
const maybe_user: ?std.json.Parsed(User) = std.json.parseFromSlice(User, self.alloc, body, .{}) catch null;
|
||||
if (maybe_user) |u| {
|
||||
defer u.deinit();
|
||||
var jsonbuf: [128]u8 = undefined;
|
||||
|
|
|
@ -16,7 +16,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
// we scope everything that can allocate within this block for leak detection
|
||||
{
|
||||
|
|
|
@ -41,12 +41,12 @@ pub fn addByName(self: *Self, first: ?[]const u8, last: ?[]const u8) !usize {
|
|||
user.lastnamelen = 0;
|
||||
|
||||
if (first) |firstname| {
|
||||
std.mem.copy(u8, user.firstnamebuf[0..], firstname);
|
||||
@memcpy(user.firstnamebuf[0..firstname.len], firstname);
|
||||
user.firstnamelen = firstname.len;
|
||||
}
|
||||
|
||||
if (last) |lastname| {
|
||||
std.mem.copy(u8, user.lastnamebuf[0..], lastname);
|
||||
@memcpy(user.lastnamebuf[0..lastname.len], lastname);
|
||||
user.lastnamelen = lastname.len;
|
||||
}
|
||||
|
||||
|
@ -101,11 +101,11 @@ pub fn update(
|
|||
pUser.firstnamelen = 0;
|
||||
pUser.lastnamelen = 0;
|
||||
if (first) |firstname| {
|
||||
std.mem.copy(u8, pUser.firstnamebuf[0..], firstname);
|
||||
@memcpy(pUser.firstnamebuf[0..firstname.len], firstname);
|
||||
pUser.firstnamelen = firstname.len;
|
||||
}
|
||||
if (last) |lastname| {
|
||||
std.mem.copy(u8, pUser.lastnamebuf[0..], lastname);
|
||||
@memcpy(pUser.lastnamebuf[0..lastname.len], lastname);
|
||||
pUser.lastnamelen = lastname.len;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@ fn setupUserData(a: std.mem.Allocator) !void {
|
|||
}
|
||||
|
||||
pub fn main() !void {
|
||||
var a = std.heap.page_allocator;
|
||||
const a = std.heap.page_allocator;
|
||||
try setupUserData(a);
|
||||
var listener = zap.SimpleHttpListener.init(.{
|
||||
.port = 3000,
|
||||
|
|
|
@ -11,10 +11,10 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
|||
var http_client: std.http.Client = .{ .allocator = a };
|
||||
defer http_client.deinit();
|
||||
|
||||
var req = try http_client.request(.GET, uri, h, .{});
|
||||
var req = try http_client.open(.GET, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
try req.wait();
|
||||
}
|
||||
|
||||
|
@ -27,7 +27,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
const Handler = struct {
|
||||
var alloc: std.mem.Allocator = undefined;
|
||||
|
@ -44,7 +44,7 @@ pub fn main() !void {
|
|||
// check for query parameters
|
||||
r.parseQuery();
|
||||
|
||||
var param_count = r.getParamCount();
|
||||
const param_count = r.getParamCount();
|
||||
std.log.info("param_count: {}", .{param_count});
|
||||
|
||||
// iterate over all params as strings
|
||||
|
|
|
@ -72,7 +72,7 @@ const UserMiddleWare = struct {
|
|||
pub fn onRequest(handler: *Handler, r: zap.SimpleRequest, context: *Context) bool {
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
const self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
|
||||
// do our work: fill in the user field of the context
|
||||
|
@ -115,7 +115,7 @@ const SessionMiddleWare = struct {
|
|||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.SimpleRequest, context: *Context) bool {
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
const self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
|
||||
context.session = Session{
|
||||
|
@ -151,7 +151,7 @@ const HtmlMiddleWare = struct {
|
|||
pub fn onRequest(handler: *Handler, r: zap.SimpleRequest, context: *Context) bool {
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
const self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
|
||||
std.debug.print("\n\nHtmlMiddleware: handling request with context: {any}\n\n", .{context});
|
||||
|
@ -190,7 +190,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
SharedAllocator.init(allocator);
|
||||
|
||||
// we create our HTML middleware component that handles the request
|
||||
|
|
|
@ -59,7 +59,7 @@ const UserMiddleWare = struct {
|
|||
pub fn onRequest(handler: *Handler, r: zap.SimpleRequest, context: *Context) bool {
|
||||
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
const self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
|
||||
// do our work: fill in the user field of the context
|
||||
|
@ -104,7 +104,7 @@ const SessionMiddleWare = struct {
|
|||
// note that the first parameter is of type *Handler, not *Self !!!
|
||||
pub fn onRequest(handler: *Handler, r: zap.SimpleRequest, context: *Context) bool {
|
||||
// this is how we would get our self pointer
|
||||
var self = @fieldParentPtr(Self, "handler", handler);
|
||||
const self = @fieldParentPtr(Self, "handler", handler);
|
||||
_ = self;
|
||||
|
||||
context.session = Session{
|
||||
|
@ -154,7 +154,7 @@ const HtmlEndpoint = struct {
|
|||
}
|
||||
|
||||
pub fn get(ep: *zap.SimpleEndpoint, r: zap.SimpleRequest) void {
|
||||
var self = @fieldParentPtr(Self, "endpoint", ep);
|
||||
const self = @fieldParentPtr(Self, "endpoint", ep);
|
||||
_ = self;
|
||||
|
||||
var buf: [1024]u8 = undefined;
|
||||
|
@ -199,7 +199,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
SharedAllocator.init(allocator);
|
||||
|
||||
// create the endpoint
|
||||
|
|
|
@ -123,7 +123,7 @@ pub fn main() !void {
|
|||
// we start a block here so the defers will run before we call the gpa
|
||||
// to detect leaks
|
||||
{
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
var listener = zap.SimpleHttpListener.init(.{
|
||||
.port = 3000,
|
||||
.on_request = on_request,
|
||||
|
|
|
@ -46,8 +46,8 @@ const ContextManager = struct {
|
|||
self.lock.lock();
|
||||
defer self.lock.unlock();
|
||||
|
||||
var ctx = try self.allocator.create(Context);
|
||||
var userName = try std.fmt.allocPrint(
|
||||
const ctx = try self.allocator.create(Context);
|
||||
const userName = try std.fmt.allocPrint(
|
||||
self.allocator,
|
||||
"{s}{d}",
|
||||
.{ self.usernamePrefix, self.contexts.items.len },
|
||||
|
@ -201,7 +201,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
GlobalContextManager = ContextManager.init(allocator, "chatroom", "user-");
|
||||
defer GlobalContextManager.deinit();
|
||||
|
|
|
@ -42,7 +42,8 @@ pub fn build_facilio(
|
|||
lib.addIncludePath(.{ .path = subdir ++ "/lib/facil/tls" });
|
||||
|
||||
// C source files
|
||||
lib.addCSourceFiles(&.{
|
||||
lib.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
subdir ++ "/lib/facil/fio.c",
|
||||
subdir ++ "/lib/facil/fio_zig.c",
|
||||
subdir ++ "/lib/facil/http/http.c",
|
||||
|
@ -59,13 +60,18 @@ pub fn build_facilio(
|
|||
subdir ++ "/lib/facil/fiobj/fiobject.c",
|
||||
subdir ++ "/lib/facil/fiobj/fiobj_mustache.c",
|
||||
subdir ++ "/lib/facil/cli/fio_cli.c",
|
||||
}, flags.items);
|
||||
},
|
||||
.flags = flags.items,
|
||||
});
|
||||
|
||||
if (use_openssl) {
|
||||
lib.addCSourceFiles(&.{
|
||||
lib.addCSourceFiles(.{
|
||||
.files = &.{
|
||||
subdir ++ "/lib/facil/tls/fio_tls_openssl.c",
|
||||
subdir ++ "/lib/facil/tls/fio_tls_missing.c",
|
||||
}, flags.items);
|
||||
},
|
||||
.flags = flags.items,
|
||||
});
|
||||
}
|
||||
|
||||
// link against libc
|
||||
|
|
44
flake.lock
generated
44
flake.lock
generated
|
@ -3,11 +3,11 @@
|
|||
"flake-compat": {
|
||||
"flake": false,
|
||||
"locked": {
|
||||
"lastModified": 1673956053,
|
||||
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
|
||||
"lastModified": 1696426674,
|
||||
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
|
||||
"owner": "edolstra",
|
||||
"repo": "flake-compat",
|
||||
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
|
||||
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -37,11 +37,11 @@
|
|||
"systems": "systems"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1689068808,
|
||||
"narHash": "sha256-6ixXo3wt24N/melDWjq70UuHQLxGV8jZvooRanIHXw0=",
|
||||
"lastModified": 1701680307,
|
||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "919d646de7be200f3bf08cb76ae1f09402b6f9b4",
|
||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -55,11 +55,11 @@
|
|||
"systems": "systems_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1685518550,
|
||||
"narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=",
|
||||
"lastModified": 1701680307,
|
||||
"narHash": "sha256-kAuep2h5ajznlPMD9rnQyffWG8EM/C73lejGofXvdM8=",
|
||||
"owner": "numtide",
|
||||
"repo": "flake-utils",
|
||||
"rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef",
|
||||
"rev": "4022d587cbbfd70fe950c1e2083a02621806a725",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -92,11 +92,11 @@
|
|||
},
|
||||
"locked": {
|
||||
"dir": "contrib",
|
||||
"lastModified": 1692702614,
|
||||
"narHash": "sha256-FeY8hAB77tnUTDbK6WYA+DG3Nx5xQrbOC17Cfl3pTm4=",
|
||||
"lastModified": 1703884419,
|
||||
"narHash": "sha256-Cth9deiBGnMhW0+QgaPJ/axiRZT1vGBZOlwLkquucMI=",
|
||||
"owner": "neovim",
|
||||
"repo": "neovim",
|
||||
"rev": "014b87646fc3273a09d6b20ebb648a8eb24a0a98",
|
||||
"rev": "c5e9acca6471280e32fbcaa30849aa68358155ca",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -108,11 +108,11 @@
|
|||
},
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1702882221,
|
||||
"narHash": "sha256-L/uOrBqkGsa45EvQk4DLq/aR6JeomW+7Mwe0mC/dVUM=",
|
||||
"lastModified": 1703875886,
|
||||
"narHash": "sha256-WJ0s5WWOBUnXAfPwxLm0cI4XjeLXPdI95Znwjrsfd2A=",
|
||||
"owner": "nixos",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "25fef6e30d8ad48f47a8411ccfe986d8baed8a15",
|
||||
"rev": "0fce51a5077927de454b94ffae41c2749fa15ba2",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
@ -124,16 +124,16 @@
|
|||
},
|
||||
"nixpkgs_2": {
|
||||
"locked": {
|
||||
"lastModified": 1689088367,
|
||||
"narHash": "sha256-Y2tl2TlKCWEHrOeM9ivjCLlRAKH3qoPUE/emhZECU14=",
|
||||
"lastModified": 1702350026,
|
||||
"narHash": "sha256-A+GNZFZdfl4JdDphYKBJ5Ef1HOiFsP18vQe9mqjmUis=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "5c9ddb86679c400d6b7360797b8a22167c2053f8",
|
||||
"rev": "9463103069725474698139ab10f17a9d125da859",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
"owner": "NixOS",
|
||||
"ref": "release-23.05",
|
||||
"ref": "nixos-23.05",
|
||||
"repo": "nixpkgs",
|
||||
"type": "github"
|
||||
}
|
||||
|
@ -184,11 +184,11 @@
|
|||
"nixpkgs": "nixpkgs_2"
|
||||
},
|
||||
"locked": {
|
||||
"lastModified": 1692663634,
|
||||
"narHash": "sha256-wioqr80UOA0tNXaJy4D0i9fFaLG2RoQi5e9Dpd4WojE=",
|
||||
"lastModified": 1703636531,
|
||||
"narHash": "sha256-gaXmic+so/NhvsXwoiM759HxE41tdFdjuepFmgXhpQE=",
|
||||
"owner": "mitchellh",
|
||||
"repo": "zig-overlay",
|
||||
"rev": "d666e5137fe0c43353c555fb47748813084decab",
|
||||
"rev": "d6cc5ac1207d2e4ae717515737fc47a705e57d76",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
23
flake.nix
23
flake.nix
|
@ -90,6 +90,7 @@
|
|||
devShells.build = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
zigpkgs."0.11.0"
|
||||
pkgs.openssl
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
|
@ -103,6 +104,28 @@
|
|||
# once we set SHELL to point to the interactive bash, neovim will
|
||||
# launch the correct $SHELL in its :terminal
|
||||
export SHELL=${pkgs.bashInteractive}/bin/bash
|
||||
export LD_LIBRARY_PATH=${pkgs.zlib.out}/lib:${pkgs.icu.out}/lib:${pkgs.openssl.out}/lib:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
|
||||
devShells.masta = pkgs.mkShell {
|
||||
nativeBuildInputs = with pkgs; [
|
||||
zigpkgs.master
|
||||
pkgs.openssl
|
||||
];
|
||||
|
||||
buildInputs = with pkgs; [
|
||||
# we need a version of bash capable of being interactive
|
||||
# as opposed to a bash just used for building this flake
|
||||
# in non-interactive mode
|
||||
bashInteractive
|
||||
];
|
||||
|
||||
shellHook = ''
|
||||
# once we set SHELL to point to the interactive bash, neovim will
|
||||
# launch the correct $SHELL in its :terminal
|
||||
export SHELL=${pkgs.bashInteractive}/bin/bash
|
||||
export LD_LIBRARY_PATH=${pkgs.zlib.out}/lib:${pkgs.icu.out}/lib:${pkgs.openssl.out}/lib:$LD_LIBRARY_PATH
|
||||
'';
|
||||
};
|
||||
|
||||
|
|
28
src/fio.zig
28
src/fio.zig
|
@ -118,10 +118,10 @@ pub const struct_fio_str_info_s = extern struct {
|
|||
pub const fio_str_info_s = struct_fio_str_info_s;
|
||||
pub extern fn http_send_body(h: [*c]http_s, data: ?*anyopaque, length: usize) c_int;
|
||||
pub fn fiobj_each1(arg_o: FIOBJ, arg_start_at: usize, arg_task: ?*const fn (FIOBJ, ?*anyopaque) callconv(.C) c_int, arg_arg: ?*anyopaque) callconv(.C) usize {
|
||||
var o = arg_o;
|
||||
var start_at = arg_start_at;
|
||||
var task = arg_task;
|
||||
var arg = arg_arg;
|
||||
const o = arg_o;
|
||||
const start_at = arg_start_at;
|
||||
const task = arg_task;
|
||||
const arg = arg_arg;
|
||||
if ((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (fiobj_type_vtable(o).*.each != null)) return fiobj_type_vtable(o).*.each.?(o, start_at, task, arg);
|
||||
return 0;
|
||||
}
|
||||
|
@ -288,8 +288,8 @@ pub const fiobj_object_header_s = extern struct {
|
|||
ref: u32,
|
||||
};
|
||||
pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize {
|
||||
var o = arg_o;
|
||||
var @"type" = arg_type;
|
||||
const o = arg_o;
|
||||
const @"type" = arg_type;
|
||||
while (true) {
|
||||
switch (@as(c_int, @bitCast(@as(c_uint, @"type")))) {
|
||||
@as(c_int, 1) => return @as(usize, @bitCast(@as(c_long, @intFromBool(((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) or (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrFromInt(o))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == FIOBJ_T_NUMBER))))),
|
||||
|
@ -311,7 +311,7 @@ pub fn fiobj_type_is(arg_o: FIOBJ, arg_type: fiobj_type_enum) callconv(.C) usize
|
|||
return @as(usize, @bitCast(@as(c_long, @intFromBool((((o != 0) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 0)))))) and ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) != @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6)))))) and (@as(c_int, @bitCast(@as(c_uint, @as([*c]fiobj_type_enum, @ptrCast(@alignCast(@as(?*anyopaque, @ptrFromInt(o & ~@as(usize, @bitCast(@as(c_long, @as(c_int, 7)))))))))[@as(c_uint, @intCast(@as(c_int, 0)))]))) == @as(c_int, @bitCast(@as(c_uint, @"type"))))))));
|
||||
}
|
||||
pub fn fiobj_type(arg_o: FIOBJ) callconv(.C) fiobj_type_enum {
|
||||
var o = arg_o;
|
||||
const o = arg_o;
|
||||
if (!(o != 0)) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NULL))));
|
||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 1))))) != 0) return @as(u8, @bitCast(@as(i8, @truncate(FIOBJ_T_NUMBER))));
|
||||
if ((o & @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) == @as(c_ulong, @bitCast(@as(c_long, @as(c_int, 6))))) return @as(u8, @bitCast(@as(u8, @truncate(o))));
|
||||
|
@ -326,7 +326,7 @@ pub extern const FIOBJECT_VTABLE_ARRAY: fiobj_object_vtable_s;
|
|||
pub extern const FIOBJECT_VTABLE_HASH: fiobj_object_vtable_s;
|
||||
pub extern const FIOBJECT_VTABLE_DATA: fiobj_object_vtable_s;
|
||||
pub fn fiobj_type_vtable(arg_o: FIOBJ) callconv(.C) [*c]const fiobj_object_vtable_s {
|
||||
var o = arg_o;
|
||||
const o = arg_o;
|
||||
while (true) {
|
||||
switch (@as(c_int, @bitCast(@as(c_uint, fiobj_type(o))))) {
|
||||
@as(c_int, 1) => return &FIOBJECT_VTABLE_NUMBER,
|
||||
|
@ -361,7 +361,7 @@ pub fn fiobj_obj2float(o: FIOBJ) callconv(.C) f64 {
|
|||
pub extern fn fio_ltocstr(c_long) fio_str_info_s;
|
||||
pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
||||
if (!(o != 0)) {
|
||||
var ret: fio_str_info_s = fio_str_info_s{
|
||||
const ret: fio_str_info_s = fio_str_info_s{
|
||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||
|
@ -374,7 +374,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
|||
switch (@as(c_int, @bitCast(@as(c_uint, @as(u8, @bitCast(@as(u8, @truncate(o)))))))) {
|
||||
@as(c_int, 6) => {
|
||||
{
|
||||
var ret: fio_str_info_s = fio_str_info_s{
|
||||
const ret: fio_str_info_s = fio_str_info_s{
|
||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("null"))),
|
||||
|
@ -384,7 +384,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
|||
},
|
||||
@as(c_int, 38) => {
|
||||
{
|
||||
var ret: fio_str_info_s = fio_str_info_s{
|
||||
const ret: fio_str_info_s = fio_str_info_s{
|
||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 5)))),
|
||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("false"))),
|
||||
|
@ -394,7 +394,7 @@ pub fn fiobj_obj2cstr(o: FIOBJ) callconv(.C) fio_str_info_s {
|
|||
},
|
||||
@as(c_int, 22) => {
|
||||
{
|
||||
var ret: fio_str_info_s = fio_str_info_s{
|
||||
const ret: fio_str_info_s = fio_str_info_s{
|
||||
.capa = @as(usize, @bitCast(@as(c_long, @as(c_int, 0)))),
|
||||
.len = @as(usize, @bitCast(@as(c_long, @as(c_int, 4)))),
|
||||
.data = @as([*c]u8, @ptrFromInt(@intFromPtr("true"))),
|
||||
|
@ -556,8 +556,8 @@ pub extern fn http_date2rfc7231(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
|||
pub extern fn http_date2rfc2109(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||
pub extern fn http_date2rfc2822(target: [*c]u8, tmbuf: [*c]struct_tm) usize;
|
||||
pub fn http_date2str(arg_target: [*c]u8, arg_tmbuf: [*c]struct_tm) callconv(.C) usize {
|
||||
var target = arg_target;
|
||||
var tmbuf = arg_tmbuf;
|
||||
const target = arg_target;
|
||||
const tmbuf = arg_tmbuf;
|
||||
return http_date2rfc7231(target, tmbuf);
|
||||
}
|
||||
pub extern fn http_time2str(target: [*c]u8, t: time_t) usize;
|
||||
|
|
|
@ -117,7 +117,7 @@ pub fn BasicAuth(comptime Lookup: type, comptime kind: BasicAuthStrategy) type {
|
|||
);
|
||||
return .AuthFailed;
|
||||
}
|
||||
var decoded = buffer[0..decoded_size];
|
||||
const decoded = buffer[0..decoded_size];
|
||||
decoder.decode(decoded, encoded) catch |err| {
|
||||
zap.debug(
|
||||
"ERROR: UserPassAuth: unable to decode `{s}`: {any}\n",
|
||||
|
@ -373,7 +373,7 @@ pub fn UserPassSessionAuth(comptime Lookup: type, comptime lockedPwLookups: bool
|
|||
lookup: *Lookup,
|
||||
args: UserPassSessionAuthArgs,
|
||||
) !Self {
|
||||
var ret: Self = .{
|
||||
const ret: Self = .{
|
||||
.allocator = allocator,
|
||||
.settings = .{
|
||||
.usernameParam = try allocator.dupe(u8, args.usernameParam),
|
||||
|
|
|
@ -210,7 +210,7 @@ test "it" {
|
|||
std.debug.print("field {} : name = {s} : type = {any}\n", .{ i, f.name, f.type });
|
||||
}
|
||||
|
||||
var mixed: Mixed = .{
|
||||
const mixed: Mixed = .{
|
||||
// it's all optionals which we made default to null in MixContexts
|
||||
};
|
||||
std.debug.print("mixed = {any}\n", .{mixed});
|
||||
|
@ -233,7 +233,7 @@ test "it" {
|
|||
};
|
||||
|
||||
// this will fail if we don't specify
|
||||
var nonOpts: NonOpts = .{
|
||||
const nonOpts: NonOpts = .{
|
||||
.user = &user,
|
||||
.session = &session,
|
||||
};
|
||||
|
|
|
@ -57,7 +57,7 @@ pub const MustacheError = error{
|
|||
pub fn mustacheNew(load_args: MustacheLoadArgs) MustacheError!*Mustache {
|
||||
var err: mustache_error_en = undefined;
|
||||
|
||||
var args: MustacheLoadArgsFio = .{
|
||||
const args: MustacheLoadArgsFio = .{
|
||||
.filename = filn: {
|
||||
if (load_args.filename) |filn| break :filn filn.ptr else break :filn null;
|
||||
},
|
||||
|
@ -73,7 +73,7 @@ pub fn mustacheNew(load_args: MustacheLoadArgs) MustacheError!*Mustache {
|
|||
.err = &err,
|
||||
};
|
||||
|
||||
var ret = fiobj_mustache_new(args);
|
||||
const ret = fiobj_mustache_new(args);
|
||||
switch (err) {
|
||||
0 => return ret.?,
|
||||
1 => return MustacheError.MUSTACHE_ERR_TOO_DEEP,
|
||||
|
@ -178,7 +178,7 @@ pub fn fiobjectify(
|
|||
},
|
||||
.Struct => |S| {
|
||||
// create a new fio hashmap
|
||||
var m = fio.fiobj_hash_new();
|
||||
const m = fio.fiobj_hash_new();
|
||||
// std.debug.print("new struct\n", .{});
|
||||
inline for (S.fields) |Field| {
|
||||
// don't include void fields
|
||||
|
@ -215,7 +215,7 @@ pub fn fiobjectify(
|
|||
return fio.fiobj_str_new(util.toCharPtr(value), value.len);
|
||||
}
|
||||
|
||||
var arr = fio.fiobj_ary_new2(value.len);
|
||||
const arr = fio.fiobj_ary_new2(value.len);
|
||||
for (value) |x| {
|
||||
const v = fiobjectify(x);
|
||||
fio.fiobj_ary_push(arr, v);
|
||||
|
|
|
@ -147,10 +147,10 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8, auth: ?ClientAuthReqHeader
|
|||
var http_client: std.http.Client = .{ .allocator = a };
|
||||
defer http_client.deinit();
|
||||
|
||||
var req = try http_client.request(.GET, uri, h, .{});
|
||||
var req = try http_client.open(.GET, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
try req.wait();
|
||||
// var br = std.io.bufferedReaderSize(std.crypto.tls.max_ciphertext_record_len, req.reader());
|
||||
// var buffer: [1024]u8 = undefined;
|
||||
|
|
|
@ -10,10 +10,10 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
|||
var http_client: std.http.Client = .{ .allocator = a };
|
||||
defer http_client.deinit();
|
||||
|
||||
var req = try http_client.request(.GET, uri, h, .{});
|
||||
var req = try http_client.open(.GET, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
try req.wait();
|
||||
zap.fio_stop();
|
||||
}
|
||||
|
@ -23,7 +23,7 @@ fn makeRequestThread(a: std.mem.Allocator, url: []const u8) !std.Thread {
|
|||
}
|
||||
|
||||
test "http parameters" {
|
||||
var allocator = std.testing.allocator;
|
||||
const allocator = std.testing.allocator;
|
||||
|
||||
const Handler = struct {
|
||||
var alloc: std.mem.Allocator = undefined;
|
||||
|
|
|
@ -15,10 +15,10 @@ fn makeRequest(a: std.mem.Allocator, url: []const u8) !void {
|
|||
var http_client: std.http.Client = .{ .allocator = a };
|
||||
defer http_client.deinit();
|
||||
|
||||
var req = try http_client.request(.GET, uri, h, .{});
|
||||
var req = try http_client.open(.GET, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
try req.wait();
|
||||
read_len = try req.readAll(&buffer);
|
||||
|
||||
|
@ -33,7 +33,7 @@ pub fn on_request(r: zap.SimpleRequest) void {
|
|||
}
|
||||
|
||||
test "send file" {
|
||||
var allocator = std.testing.allocator;
|
||||
const allocator = std.testing.allocator;
|
||||
|
||||
// setup listener
|
||||
var listener = zap.SimpleHttpListener.init(
|
||||
|
|
|
@ -43,7 +43,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
|
||||
/// This function will end the HTTP stage of the connection and attempt to "upgrade" to a WebSockets connection.
|
||||
pub fn upgrade(h: [*c]fio.http_s, settings: *WebSocketSettings) WebSocketError!void {
|
||||
var fio_settings: fio.websocket_settings_s = .{
|
||||
const fio_settings: fio.websocket_settings_s = .{
|
||||
.on_message = internal_on_message,
|
||||
.on_open = internal_on_open,
|
||||
.on_ready = internal_on_ready,
|
||||
|
@ -57,8 +57,8 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
}
|
||||
|
||||
fn internal_on_message(handle: WsHandle, msg: fio.fio_str_info_s, is_text: u8) callconv(.C) void {
|
||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
var message = msg.data[0..msg.len];
|
||||
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
const message = msg.data[0..msg.len];
|
||||
if (user_provided_settings) |settings| {
|
||||
if (settings.on_message) |on_message| {
|
||||
on_message(settings.context, handle, message, is_text == 1);
|
||||
|
@ -67,7 +67,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
}
|
||||
|
||||
fn internal_on_open(handle: WsHandle) callconv(.C) void {
|
||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
if (user_provided_settings) |settings| {
|
||||
if (settings.on_open) |on_open| {
|
||||
on_open(settings.context, handle);
|
||||
|
@ -76,7 +76,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
}
|
||||
|
||||
fn internal_on_ready(handle: WsHandle) callconv(.C) void {
|
||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
if (user_provided_settings) |settings| {
|
||||
if (settings.on_ready) |on_ready| {
|
||||
on_ready(settings.context, handle);
|
||||
|
@ -85,7 +85,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
}
|
||||
|
||||
fn internal_on_shutdown(handle: WsHandle) callconv(.C) void {
|
||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(fio.websocket_udata_get(handle))));
|
||||
if (user_provided_settings) |settings| {
|
||||
if (settings.on_shutdown) |on_shutdown| {
|
||||
on_shutdown(settings.context, handle);
|
||||
|
@ -94,7 +94,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
}
|
||||
|
||||
fn internal_on_close(uuid: isize, udata: ?*anyopaque) callconv(.C) void {
|
||||
var user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
||||
const user_provided_settings: ?*WebSocketSettings = @as(?*WebSocketSettings, @ptrCast(@alignCast(udata)));
|
||||
if (user_provided_settings) |settings| {
|
||||
if (settings.on_close) |on_close| {
|
||||
on_close(settings.context, uuid);
|
||||
|
@ -170,7 +170,7 @@ pub fn Handler(comptime ContextType: type) type {
|
|||
/// we need it to look up the ziggified callbacks.
|
||||
pub inline fn subscribe(handle: WsHandle, args: *SubscribeArgs) WebSocketError!usize {
|
||||
if (handle == null) return error.SubscribeError;
|
||||
var fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
||||
const fio_args: fio.websocket_subscribe_s_zigcompat = .{
|
||||
.ws = handle.?,
|
||||
.channel = util.str2fio(args.channel),
|
||||
.on_message = if (args.on_message) |_| internal_subscription_on_message else null,
|
||||
|
|
18
src/zap.zig
18
src/zap.zig
|
@ -142,8 +142,8 @@ pub const SimpleRequest = struct {
|
|||
var writer = string.writer();
|
||||
try writer.print("ERROR: {any}\n\n", .{err});
|
||||
|
||||
var debugInfo = try std.debug.getSelfDebugInfo();
|
||||
var ttyConfig: std.io.tty.Config = .no_color;
|
||||
const debugInfo = try std.debug.getSelfDebugInfo();
|
||||
const ttyConfig: std.io.tty.Config = .no_color;
|
||||
try std.debug.writeCurrentStackTrace(writer, debugInfo, ttyConfig, null);
|
||||
try self.sendBody(string.items);
|
||||
}
|
||||
|
@ -297,7 +297,7 @@ pub const SimpleRequest = struct {
|
|||
|
||||
// Set a response cookie
|
||||
pub fn setCookie(self: *const Self, args: CookieArgs) HttpError!void {
|
||||
var c: fio.http_cookie_args_s = .{
|
||||
const c: fio.http_cookie_args_s = .{
|
||||
.name = util.toCharPtr(args.name),
|
||||
.name_len = @as(isize, @intCast(args.name.len)),
|
||||
.value = util.toCharPtr(args.value),
|
||||
|
@ -414,7 +414,7 @@ pub const SimpleRequest = struct {
|
|||
fn _each_nextParamStr(fiobj_value: fio.FIOBJ, context: ?*anyopaque) callconv(.C) c_int {
|
||||
const ctx: *_parametersToOwnedStrSliceContext = @as(*_parametersToOwnedStrSliceContext, @ptrCast(@alignCast(context)));
|
||||
// this is thread-safe, guaranteed by fio
|
||||
var fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
ctx.params.append(.{
|
||||
.key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.always_alloc) catch |err| {
|
||||
ctx.last_error = err;
|
||||
|
@ -467,7 +467,7 @@ pub const SimpleRequest = struct {
|
|||
fn _each_nextParam(fiobj_value: fio.FIOBJ, context: ?*anyopaque) callconv(.C) c_int {
|
||||
const ctx: *_parametersToOwnedSliceContext = @as(*_parametersToOwnedSliceContext, @ptrCast(@alignCast(context)));
|
||||
// this is thread-safe, guaranteed by fio
|
||||
var fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
const fiobj_key: fio.FIOBJ = fio.fiobj_hash_key_in_loop();
|
||||
ctx.params.append(.{
|
||||
.key = util.fio2strAllocOrNot(fiobj_key, ctx.allocator, ctx.dupe_strings) catch |err| {
|
||||
ctx.last_error = err;
|
||||
|
@ -846,7 +846,7 @@ pub const SimpleHttpListener = struct {
|
|||
._is_finished_request_global = false,
|
||||
._user_context = undefined,
|
||||
};
|
||||
var zigtarget: []u8 = target[0..target_len];
|
||||
const zigtarget: []u8 = target[0..target_len];
|
||||
req._is_finished = &req._is_finished_request_global;
|
||||
|
||||
var user_context: SimpleRequest.UserContext = .{};
|
||||
|
@ -872,7 +872,7 @@ pub const SimpleHttpListener = struct {
|
|||
pfolder = pf.ptr;
|
||||
}
|
||||
|
||||
var x: fio.http_settings_s = .{
|
||||
const x: fio.http_settings_s = .{
|
||||
.on_request = if (self.settings.on_request) |_| Self.theOneAndOnlyRequestCallBack else null,
|
||||
.on_upgrade = if (self.settings.on_upgrade) |_| Self.theOneAndOnlyUpgradeCallBack else null,
|
||||
.on_response = if (self.settings.on_response) |_| Self.theOneAndOnlyResponseCallBack else null,
|
||||
|
@ -906,7 +906,7 @@ pub const SimpleHttpListener = struct {
|
|||
// const result = try bufPrint(buf, fmt ++ "\x00", args);
|
||||
// return result[0 .. result.len - 1 :0];
|
||||
// }
|
||||
var ret = fio.http_listen(printed_port.ptr, self.settings.interface, x);
|
||||
const ret = fio.http_listen(printed_port.ptr, self.settings.interface, x);
|
||||
if (ret == -1) {
|
||||
return error.ListenError;
|
||||
}
|
||||
|
@ -951,7 +951,7 @@ pub fn listen(port: [*c]const u8, interface: [*c]const u8, settings: ListenSetti
|
|||
pfolder_len = pf.len;
|
||||
pfolder = pf.ptr;
|
||||
}
|
||||
var x: fio.http_settings_s = .{
|
||||
const x: fio.http_settings_s = .{
|
||||
.on_request = settings.on_request,
|
||||
.on_upgrade = settings.on_upgrade,
|
||||
.on_response = settings.on_response,
|
||||
|
|
|
@ -88,7 +88,7 @@ fn get_tag_annotation(allocator: std.mem.Allocator, tagname: []const u8) ![]cons
|
|||
tagname,
|
||||
};
|
||||
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = allocator,
|
||||
.argv = &args,
|
||||
});
|
||||
|
@ -161,13 +161,13 @@ fn sendToDiscordPart(allocator: std.mem.Allocator, url: []const u8, message_json
|
|||
defer http_client.deinit();
|
||||
|
||||
// request
|
||||
var req = try http_client.request(.POST, uri, h, .{});
|
||||
var req = try http_client.open(.POST, uri, h, .{});
|
||||
defer req.deinit();
|
||||
|
||||
req.transfer_encoding = .chunked;
|
||||
|
||||
// connect, send request
|
||||
try req.start();
|
||||
try req.send(.{});
|
||||
|
||||
// send POST payload
|
||||
try req.writer().writeAll(message_json);
|
||||
|
@ -182,7 +182,7 @@ fn sendToDiscordPart(allocator: std.mem.Allocator, url: []const u8, message_json
|
|||
fn sendToDiscord(allocator: std.mem.Allocator, url: []const u8, message: []const u8) !void {
|
||||
// json payload
|
||||
// max size: 100kB
|
||||
var buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
||||
const buf: []u8 = try allocator.alloc(u8, 100 * 1024);
|
||||
defer allocator.free(buf);
|
||||
var fba = std.heap.FixedBufferAllocator.init(buf);
|
||||
var string = std.ArrayList(u8).init(fba.allocator());
|
||||
|
@ -399,7 +399,7 @@ fn command_update_readme(allocator: std.mem.Allocator, tag: []const u8) !void {
|
|||
// we need to put the \n back in.
|
||||
// TODO: change this by using some "search" iterator that just
|
||||
// returns indices etc
|
||||
var output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
||||
const output_line = try std.fmt.allocPrint(allocator, "{s}\n", .{line});
|
||||
defer allocator.free(output_line);
|
||||
_ = try writer.write(output_line);
|
||||
}
|
||||
|
|
|
@ -71,7 +71,7 @@ pub const usage_pkg =
|
|||
;
|
||||
|
||||
pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &.{
|
||||
"git",
|
||||
|
@ -97,7 +97,7 @@ pub fn gitLatestTag(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
|||
}
|
||||
|
||||
pub fn gitFileList(gpa: Allocator, pkg_dir: []const u8) ![]const u8 {
|
||||
const result = try std.ChildProcess.exec(.{
|
||||
const result = try std.ChildProcess.run(.{
|
||||
.allocator = gpa,
|
||||
.argv = &.{
|
||||
"git",
|
||||
|
@ -266,8 +266,8 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
|||
|
||||
// computePackageHash will close the directory after completion
|
||||
// std.debug.print("abspath: {s}\n", .{cwd_absolute_path});
|
||||
var cwd_copy = try fs.openIterableDirAbsolute(cwd_absolute_path, .{});
|
||||
errdefer cwd_copy.dir.close();
|
||||
var cwd_copy = try fs.openDirAbsolute(cwd_absolute_path, .{});
|
||||
errdefer cwd_copy.close();
|
||||
|
||||
var thread_pool: ThreadPool = undefined;
|
||||
try thread_pool.init(.{ .allocator = gpa });
|
||||
|
@ -281,7 +281,7 @@ pub fn cmdPkg(gpa: Allocator, arena: Allocator, args: []const []const u8) !void
|
|||
};
|
||||
break :blk try computePackageHashExcludingDirectories(
|
||||
&thread_pool,
|
||||
.{ .dir = cwd_copy.dir },
|
||||
cwd_copy,
|
||||
excluded_directories,
|
||||
);
|
||||
};
|
||||
|
@ -355,7 +355,7 @@ fn isExecutable(file: fs.File) !bool {
|
|||
|
||||
pub fn computePackageHashExcludingDirectories(
|
||||
thread_pool: *ThreadPool,
|
||||
pkg_dir: fs.IterableDir,
|
||||
pkg_dir: fs.Dir,
|
||||
excluded_directories: []const []const u8,
|
||||
) ![Manifest.Hash.digest_length]u8 {
|
||||
const gpa = thread_pool.allocator;
|
||||
|
@ -405,7 +405,7 @@ pub fn computePackageHashExcludingDirectories(
|
|||
.failure = undefined, // to be populated by the worker
|
||||
};
|
||||
wait_group.start();
|
||||
try thread_pool.spawn(workerHashFile, .{ pkg_dir.dir, hashed_file, &wait_group });
|
||||
try thread_pool.spawn(workerHashFile, .{ pkg_dir, hashed_file, &wait_group });
|
||||
|
||||
try all_files.append(hashed_file);
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@ pub fn main() !void {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{
|
||||
.thread_safe = true,
|
||||
}){};
|
||||
var allocator = gpa.allocator();
|
||||
const allocator = gpa.allocator();
|
||||
|
||||
var server = std.http.Server.init(allocator, .{
|
||||
.reuse_address = true,
|
||||
|
@ -30,7 +30,7 @@ pub fn main() !void {
|
|||
res.transfer_encoding = .{ .content_length = server_body.len };
|
||||
try res.headers.append("content-type", "text/plain");
|
||||
try res.headers.append("connection", "close");
|
||||
try res.do();
|
||||
try res.send();
|
||||
|
||||
var buf: [128]u8 = undefined;
|
||||
_ = try res.readAll(&buf);
|
||||
|
|
Loading…
Add table
Reference in a new issue