authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-04 17:19:06 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-04 17:19:06 -08:00
log35c825684f20432b7eb917ea84c81ab990322a48
tree885efed4374882f55d5ae48b34a5dd9d66912a82
parenta017ade68e7be106b1c8b9cc3b72f5fb2f92dfe8
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

use zig-net-http for response_headers param


1 files changed, 8 insertions(+), 8 deletions(-)

oauth2.zig+8-8
......@@ -255,7 +255,7 @@ pub fn Handlers(comptime T: type) type {
255255 const Self = @This();
256256 pub var clients: []Client = &.{};
257257
258 pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
258 pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void {
259259 if (query.get("with")) |with| {
260260 const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{});
261261 return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers);
......@@ -264,7 +264,7 @@ pub fn Handlers(comptime T: type) type {
264264 return try loginOne(request, alloc, T, clients[0], T.callbackPath, request_headers, response_status, response_headers);
265265 }
266266
267 try response_headers.append(alloc, .{ .name = "Content-Type", .value = "text/html" });
267 try response_headers.append("content-type", "text/html");
268268 const page = files.@"/selector.pek";
269269 const tmpl = comptime pek.parse(page);
270270 try pek.compile(Base, alloc, body_writer, tmpl, .{
......@@ -272,7 +272,7 @@ pub fn Handlers(comptime T: type) type {
272272 });
273273 }
274274
275 pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
275 pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void {
276276 _ = request;
277277 const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{});
278278 const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state});
......@@ -321,15 +321,15 @@ pub fn Handlers(comptime T: type) type {
321321 const name = val2.value.object.get(client.provider.name_prop).?.string;
322322 try T.saveInfo(response_headers, alloc, client.provider, id, name, val.value, val2.value);
323323
324 try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl });
324 try response_headers.append("location", T.doneUrl);
325325 response_status.* = .found;
326326 }
327327 };
328328}
329329
330fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void {
330fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *http.Status, response_headers: *http.HeadersMap) !void {
331331 if (try T.isLoggedIn(request, alloc)) {
332 try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl });
332 try response_headers.append("location", T.doneUrl);
333333 } else {
334334 const idp = client.provider;
335335 var params = url.SearchParams.init(alloc);
......@@ -340,7 +340,7 @@ fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T:
340340 try params.append("duration", "temporary");
341341 try params.append("state", idp.id);
342342 const authurl = try std.mem.join(alloc, "?", &.{ idp.authorize_url, try params.encode() });
343 try response_headers.append(alloc, .{ .name = "Location", .value = authurl });
343 try response_headers.append("location", authurl);
344344 }
345345 response_status.* = .found;
346346}
......@@ -351,7 +351,7 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin
351351}
352352
353353fn redirectUri(request_headers: *const std.StringHashMapUnmanaged(string), alloc: std.mem.Allocator, callbackPath: string) !string {
354 const xproto = request_headers.get("X-Forwarded-Proto") orelse "";
354 const xproto = request_headers.get("x-forwarded-proto") orelse "";
355355 const maybe_tls = std.mem.eql(u8, xproto, "https");
356356 const proto: string = if (maybe_tls) "https" else "http";
357357 const host = request_headers.get("host").?;