From 3a4d58d06bdfbe4e6adb1219c580d07adb8a3488 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Tue, 3 Mar 2026 02:03:42 -0800 Subject: [PATCH] replace UrlValues with url.SearchParams --- licenses.txt | 4 +++- oauth2.zig | 10 +++++----- zig.mod | 2 +- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/licenses.txt b/licenses.txt index 86b74a8ba86dbb53492de59fc46a5c433b0f51dd..bb0b48cacd790fd60631e386c33cac36783b9656 100644 --- a/licenses.txt +++ b/licenses.txt @@ -3,16 +3,18 @@ MIT: - This - git https://github.com/nektro/iguanaTLS - git https://github.com/nektro/zfetch -- git https://github.com/nektro/zig-UrlValues - git https://github.com/nektro/zig-extras - git https://github.com/nektro/zig-sys-linux - git https://github.com/nektro/zig-tracer +- git https://github.com/nektro/zig-unicode-ucd - git https://github.com/truemedian/hzzp - git https://github.com/kivikakk/htmlentities.zig MPL-2.0: = https://spdx.org/licenses/MPL-2.0 - git https://github.com/nektro/zig-pek +- git https://github.com/nektro/zig-unicode-idna +- git https://github.com/nektro/zig-whatwg-url Unspecified: - system_lib c diff --git a/oauth2.zig b/oauth2.zig index f4f967f8cef66167b4a8a5fa9011869a22b48147..90b0915dc2847812e8a4a79f2265a95a8e59855b 100644 --- a/oauth2.zig +++ b/oauth2.zig @@ -6,7 +6,7 @@ const files = @import("./files.zig"); const pek = @import("pek"); const zfetch = @import("zfetch"); const extras = @import("extras"); -const UrlValues = @import("UrlValues"); +const url = @import("url"); const Base = @This(); pub const Provider = struct { @@ -254,7 +254,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: UrlValues, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { + 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 { 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,13 +271,13 @@ pub fn Handlers(comptime T: type) type { }); } - pub fn callback(request: *std.http.Server.Request, body_writer: anytype, alloc: std.mem.Allocator, query: UrlValues, request_headers: *const std.StringHashMapUnmanaged(string), response_status: *std.http.Status, response_headers: *std.ArrayListUnmanaged(std.http.Header)) !void { + 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 { _ = 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}); const code = query.get("code") orelse return try fail(response_status, body_writer, "", .{}); - var params = UrlValues.init(alloc); + var params = url.SearchParams.init(alloc); try params.append("client_id", client.id); try params.append("client_secret", client.secret); try params.append("grant_type", "authorization_code"); @@ -331,7 +331,7 @@ fn loginOne(request: *std.http.Server.Request, alloc: std.mem.Allocator, comptim try response_headers.append(alloc, .{ .name = "Location", .value = T.doneUrl }); } else { const idp = client.provider; - var params = UrlValues.init(alloc); + var params = url.SearchParams.init(alloc); try params.append("client_id", client.id); try params.append("redirect_uri", try redirectUri(request_headers, alloc, callbackPath)); try params.append("response_type", "code"); diff --git a/zig.mod b/zig.mod index 6afb69b173fdeeb8b0d3409a1b61a6c41d18a071..8956960d8dbf09432791045c067403c036a8e4d9 100644 --- a/zig.mod +++ b/zig.mod @@ -9,4 +9,4 @@ dependencies: - src: git https://github.com/nektro/zig-pek - src: git https://github.com/nektro/zfetch - src: git https://github.com/nektro/zig-extras - - src: git https://github.com/nektro/zig-UrlValues + - src: git https://github.com/nektro/zig-whatwg-url -- 2.54.0