srctree

Gregory Mullen parent 7a5c7081 e9aba6a1
change server API to include auth

no, i don't really like it, in fact, I hate this, but I can fix it in post
src/http.zig added: 44, removed: 30, total 14
@@ -1,26 +1,30 @@
//! Verse HTTP server
const HTTP = @This();
 
const MAX_HEADER_SIZE = 1 <<| 13;
 
alloc: Allocator,
listen_addr: std.net.Address,
router: Router,
auth: Auth.Provider,
 
listen_addr: std.net.Address,
max_request_size: usize = 0xffff,
request_buffer: [0xffff]u8 = undefined,
running: bool = true,
alive: bool = false,
 
const HTTP = @This();
 
const MAX_HEADER_SIZE = 1 <<| 13;
 
pub const Options = struct {
host: []const u8 = "127.0.0.1",
port: u16 = 8080,
};
 
pub fn init(a: Allocator, opts: Options, router: Router) !HTTP {
pub fn init(a: Allocator, opts: Options, sopts: VServer.Options) !HTTP {
return .{
.alloc = a,
.router = sopts.router,
.auth = sopts.auth,
.listen_addr = try std.net.Address.parseIp(opts.host, opts.port),
.router = router,
};
}
 
@@ -99,7 +103,7 @@ fn threadFn(server: *HTTP) void {
 
test HTTP {
const a = std.testing.allocator;
var server = try init(a, .{ .port = 9345 }, .{ .routefn = Router.testingRouter });
var server = try init(a, .{ .port = 9345 }, .{ .router = .{ .routefn = Router.testingRouter } });
var thread = try std.Thread.spawn(.{}, threadFn, .{&server});
 
var client = std.http.Client{ .allocator = a };
@@ -119,6 +123,8 @@ test HTTP {
thread.join();
}
 
const Auth = @import("auth.zig");
const VServer = @import("server.zig");
const Frame = @import("frame.zig");
const Router = @import("router.zig");
const Request = @import("request.zig");
 
src/server.zig added: 44, removed: 30, total 14
@@ -33,8 +33,8 @@ pub fn init(a: Allocator, opts: Options) !Server {
.alloc = a,
.router = opts.router,
.interface = switch (opts.mode) {
.zwsgi => |z| .{ .zwsgi = zWSGI.init(a, z, opts.router) },
.http => |h| .{ .http = try Http.init(a, h, opts.router) },
.zwsgi => |z| .{ .zwsgi = zWSGI.init(a, z, opts) },
.http => |h| .{ .http = try Http.init(a, h, opts) },
.other => unreachable,
},
};
 
src/zwsgi.zig added: 44, removed: 30, total 14
@@ -1,32 +1,26 @@
const std = @import("std");
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.Verse);
const net = std.net;
const siginfo_t = std.posix.siginfo_t;
const SIG = std.posix.SIG;
const SA = std.posix.SA;
 
const Frame = @import("frame.zig");
const Request = @import("request.zig");
const Router = @import("router.zig");
 
const zWSGI = @This();
//! Verse zwsgi server
//! Speaks the uwsgi protocol
 
alloc: Allocator,
unix_file: []const u8,
options: Options,
router: Router,
options: Options,
auth: Auth.Provider,
 
unix_file: []const u8,
 
const zWSGI = @This();
 
pub const Options = struct {
file: []const u8 = "./zwsgi_file.sock",
chmod: ?std.posix.mode_t = null,
};
 
pub fn init(a: Allocator, opts: Options, router: Router) zWSGI {
pub fn init(a: Allocator, opts: Options, sopts: Server.Options) zWSGI {
return .{
.alloc = a,
.unix_file = opts.file,
.router = router,
.router = sopts.router,
.auth = sopts.auth,
.options = opts,
};
}
@@ -268,5 +262,19 @@ test init {
}
};
 
_ = init(a, .{}, .{ .routefn = R.route });
_ = init(a, .{}, .{ .router = .{ .routefn = R.route } });
}
 
const std = @import("std");
const Allocator = std.mem.Allocator;
const log = std.log.scoped(.Verse);
const net = std.net;
const siginfo_t = std.posix.siginfo_t;
const SIG = std.posix.SIG;
const SA = std.posix.SA;
 
const Server = @import("server.zig");
const Frame = @import("frame.zig");
const Request = @import("request.zig");
const Router = @import("router.zig");
const Auth = @import("auth.zig");