From a017ade68e7be106b1c8b9cc3b72f5fb2f92dfe8 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Wed, 4 Mar 2026 03:55:15 -0800 Subject: [PATCH] switch to using nektro/zig-net-http --- oauth2.zig | 9 +++++---- zig.mod | 1 + 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/oauth2.zig b/oauth2.zig index 90b0915dc2847812e8a4a79f2265a95a8e59855b..a5fd571874b12e2d463c61604bcad338d66342fa 100644 --- a/oauth2.zig +++ b/oauth2.zig @@ -7,6 +7,7 @@ const pek = @import("pek"); const zfetch = @import("zfetch"); const extras = @import("extras"); const url = @import("url"); +const http = @import("http"); const Base = @This(); pub const Provider = struct { @@ -254,7 +255,7 @@ pub fn Handlers(comptime T: type) type { const Self = @This(); pub var clients: []Client = &.{}; - pub fn login(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { + 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 { if (query.get("with")) |with| { const client = clientByProviderId(Self.clients, with) orelse return try fail(response_status, body_writer, "Client with that ID not found!\n", .{}); return try loginOne(request, alloc, T, client, T.callbackPath, request_headers, response_status, response_headers); @@ -271,7 +272,7 @@ pub fn Handlers(comptime T: type) type { }); } - pub fn callback(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: url.SearchParams, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { + 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 { _ = request; const state = query.get("state") orelse return try fail(response_status, body_writer, "", .{}); const client = clientByProviderId(Self.clients, state) orelse return try fail(response_status, body_writer, "error: No handler found for provider: {s}\n", .{state}); @@ -326,7 +327,7 @@ pub fn Handlers(comptime T: type) type { }; } -fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptime T: type, client: Client, callbackPath: string, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { +fn 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 { if (try T.isLoggedIn(request, alloc)) { try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl }); } else { @@ -344,7 +345,7 @@ fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptim response_status.* = .found; } -fn fail(response_status: *std.http.Status, body_writer: anytype, comptime err: string, args: anytype) !void { +fn fail(response_status: *http.Status, body_writer: anytype, comptime err: string, args: anytype) !void { response_status.* = .bad_request; try body_writer.print(err, args); } diff --git a/zig.mod b/zig.mod index 8956960d8dbf09432791045c067403c036a8e4d9..9d0b1d8ae152429508f1741a51975c5b7e15e1e9 100644 --- a/zig.mod +++ b/zig.mod @@ -10,3 +10,4 @@ dependencies: - src: git https://github.com/nektro/zfetch - src: git https://github.com/nektro/zig-extras - src: git https://github.com/nektro/zig-whatwg-url + - src: git https://github.com/nektro/zig-net-http -- 2.54.0