Skip to content

Commit f9d48b0

Browse files
committed
More refactor and add getHeader method
1 parent bc75855 commit f9d48b0

File tree

4 files changed

+237
-190
lines changed

4 files changed

+237
-190
lines changed

examples/hello/greeter.zig

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,13 @@ fn defaultHeaders(ctx: *zin.Context) !void {
3535
try ctx.headers.append(.{ .name = "server", .value = "zin/v0.1.0" });
3636
}
3737

38+
fn auth(ctx: *zin.Context) !void {
39+
const authorization = try ctx.getHeader("Authorization");
40+
if (authorization.len == 0) {
41+
try ctx.text(.unauthorized, "missing authorization header");
42+
}
43+
}
44+
3845
pub fn main() !void {
3946
var app = try zin.new(.{});
4047
defer app.deinit();
@@ -43,6 +50,7 @@ pub fn main() !void {
4350
try app.use(zin.mw.queryStringParser);
4451

4552
try app.use(defaultHeaders);
53+
try app.use(auth);
4654

4755
// use classic route templating syntax to register handlers
4856
try app.get("/greet/:name", greet);

0 commit comments

Comments
 (0)