summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--build.zig2
-rw-r--r--build.zig.zon1
-rw-r--r--src/main.zig4
-rw-r--r--src/zigwebserver.zig10
4 files changed, 9 insertions, 8 deletions
diff --git a/build.zig b/build.zig
index 087d7ae..ae532eb 100644
--- a/build.zig
+++ b/build.zig
@@ -33,7 +33,7 @@ pub fn build(b: *std.Build) void {
b.installArtifact(lib);
// for zig module system
- _ = b.addModule("zigwebserver", .{ .source_file = .{ .path = "src/zigwebserver.zig" } });
+ _ = b.addModule("zigwebserver", .{ .root_source_file = .{ .path = "src/zigwebserver.zig" } });
// This declares intent for the executable to be installed into the
// standard location when the user invokes the "install" step (the default
diff --git a/build.zig.zon b/build.zig.zon
index bfb4c54..7b03c63 100644
--- a/build.zig.zon
+++ b/build.zig.zon
@@ -1,4 +1,5 @@
.{
.name = "zigwebserver",
.version = "0.0.1",
+ .paths = .{""},
}
diff --git a/src/main.zig b/src/main.zig
index 70869b2..11f6d0d 100644
--- a/src/main.zig
+++ b/src/main.zig
@@ -39,7 +39,7 @@ const Handler = struct {
fn serve_file(res: *std.http.Server.Response, file: std.fs.File, md: std.fs.File.Metadata) !void {
res.transfer_encoding = .{ .content_length = md.size() };
- try res.do();
+ try res.send();
var buf = [_]u8{0} ** 1024;
while (true) {
const read = try file.read(&buf);
@@ -51,7 +51,7 @@ const Handler = struct {
fn serve_error(res: *std.http.Server.Response, status: std.http.Status) !void {
res.status = status;
res.transfer_encoding = .chunked;
- try res.do();
+ try res.send();
const phrase = status.phrase() orelse "error!";
try std.fmt.format(res.writer(),
\\ <!doctype html><html><body>{s}</body></html>
diff --git a/src/zigwebserver.zig b/src/zigwebserver.zig
index acf65fb..64bd649 100644
--- a/src/zigwebserver.zig
+++ b/src/zigwebserver.zig
@@ -19,7 +19,7 @@ pub fn Server(comptime Context: type, comptime Handler: type) type {
try tp.init(.{ .allocator = self.allocator, .n_jobs = self.n_threads });
defer tp.deinit();
- var svr_internal = std.http.Server.init(self.allocator, .{ .reuse_address = true });
+ var svr_internal = std.http.Server.init(.{ .reuse_address = true });
defer svr_internal.deinit();
try svr_internal.listen(self.address);
std.log.info("server listening on {}", .{self.address});
@@ -57,7 +57,7 @@ pub fn Server(comptime Context: type, comptime Handler: type) type {
res.status = status;
res.transfer_encoding = .{ .content_length = content.len };
try res.headers.append("content-type", "text/html");
- try res.do();
+ try res.send();
try res.writer().writeAll(content);
try res.finish();
}
@@ -185,7 +185,7 @@ const RouterTest = struct {
.method = .GET,
.target = target,
};
- var res = TestResponse{
+ const res = TestResponse{
.request = req,
};
const router = TestRouter{
@@ -225,8 +225,8 @@ const RouterTest = struct {
var it = pexp.keyIterator();
var kexp = it.next();
while (kexp != null) : (kexp = it.next()) {
- var vexp = pexp.get(kexp.?.*).?;
- var maybe_vact = pact.get(kexp.?.*);
+ const vexp = pexp.get(kexp.?.*).?;
+ const maybe_vact = pact.get(kexp.?.*);
if (maybe_vact) |vact| {
std.debug.print("{s} {s}", .{ vexp, vact });
try std.testing.expectEqual(vexp, vact);