Skip to content

Commit

Permalink
handler- add _internal.redirectTo
Browse files Browse the repository at this point in the history
  • Loading branch information
nektro committed Jan 29, 2022
1 parent af4bc02 commit 25961c1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 6 additions & 2 deletions src/handler/_internal.zig
Original file line number Diff line number Diff line change
Expand Up @@ -92,9 +92,8 @@ pub const JWT = struct {
pub fn getUser(response: *http.Response, request: http.Request) !db.User {
const x = JWT.veryifyRequest(request) catch |err| switch (err) {
error.NoTokenFound, error.InvalidSignature => |e| {
try response.headers.put("Location", "./login");
try response.headers.put("X-Jwt-Fail", @errorName(e));
try response.writeHeader(.found);
try redirectTo(response, "./login");
return error.HttpNoOp;
},
else => return err,
Expand Down Expand Up @@ -209,3 +208,8 @@ pub fn rename(old_path: string, new_path: string) !void {
else => |e| return e,
};
}

pub fn redirectTo(response: *http.Response, dest: string) !void {
try response.headers.put("Location", dest);
try response.writeHeader(.found);
}
3 changes: 1 addition & 2 deletions src/handler/do_import.zig
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,5 @@ pub fn get(_: void, response: *http.Response, request: http.Request, args: struc
try std.mem.concat(alloc, u8, &.{ "https://", root.domain, desturl, "/hook?secret=", p.hook_secret }),
);

try response.headers.put("Location", try std.mem.concat(alloc, u8, &.{ ".", desturl }));
try response.writeHeader(.found);
try _internal.redirectTo(response, try std.mem.concat(alloc, u8, &.{ ".", desturl }));
}

0 comments on commit 25961c1

Please sign in to comment.