authorgravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-05 00:05:04 -08:00
committergravatar for hello@nektro.netMeghan Denny <hello@nektro.net> 2026-03-05 00:05:04 -08:00
loge9ca92b847a56e14e462f5ed756ca55e8f623a3d
tree70feb63d78a10a3a433f8e8fc3d1274270302da6
parent35c825684f20432b7eb917ea84c81ab990322a48
signaturebadge-check Signed by SSH key SHA256:4hHJbtBRU58AYXwjL7fkz2fnQHdiye8x1QpTCQ0sHNw

more zig-net-http changes


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

oauth2.zig+6-6
......@@ -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: *http.HeadersMap) !void {
258 pub fn login(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const http.HeadersMap, 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);
......@@ -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: *http.HeadersMap) !void {
275 pub fn callback(request: *http.ServerRequest, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const http.HeadersMap, 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});
......@@ -327,7 +327,7 @@ pub fn Handlers(comptime T: type) type {
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: *http.HeadersMap) !void {
330fn loginOne(request: *http.ServerRequest, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const http.HeadersMap, response_status: *http.Status, response_headers: *http.HeadersMap) !void {
331331 if (try T.isLoggedIn(request, alloc)) {
332332 try response_headers.append("location", T.doneUrl);
333333 } else {
......@@ -350,11 +350,11 @@ fn fail(response_status: *http.Status, body_writer: anytype, comptime err: strin
350350 try body_writer.print(err, args);
351351}
352352
353fn redirectUri(request_headers: *const std.StringHashMapUnmanaged(string), alloc: std.mem.Allocator, callbackPath: string) !string {
354 const xproto = request_headers.get("x-forwarded-proto") orelse "";
353fn redirectUri(request_headers: *const http.HeadersMap, alloc: std.mem.Allocator, callbackPath: string) !string {
354 const xproto = request_headers.find("x-forwarded-proto") orelse "";
355355 const maybe_tls = std.mem.eql(u8, xproto, "https");
356356 const proto: string = if (maybe_tls) "https" else "http";
357 const host = request_headers.get("host").?;
357 const host = request_headers.find("host").?;
358358 return try std.fmt.allocPrint(alloc, "{s}://{s}{s}", .{ proto, host, callbackPath });
359359}
360360