From 27873c7ccc0aed3bd3694fe2250d2cf2fd8101e5 Mon Sep 17 00:00:00 2001 From: Meghan Denny Date: Sun, 31 May 2026 23:44:23 -0700 Subject: [PATCH] update to zig 0.15.2 --- README.md | 2 +- oauth2.zig | 32 ++++++++++++++------------------ 2 files changed, 15 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index 695f29754fd43c7ac28d3a28490955ea178d1e95..05a13cc7b011030984ef8c9914e798529b327024 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ ![loc](https://sloc.xyz/github/nektro/zig-oauth2) [![license](https://img.shields.io/github/license/nektro/zig-oauth2.svg)](https://github.com/nektro/zig-oauth2/blob/master/LICENSE) [![nektro @ github sponsors](https://img.shields.io/badge/sponsors-nektro-purple?logo=github)](https://github.com/sponsors/nektro) -[![Zig](https://img.shields.io/badge/Zig-0.14-f7a41d)](https://ziglang.org/) +[![Zig](https://img.shields.io/badge/Zig-0.15-f7a41d)](https://ziglang.org/) [![Zigmod](https://img.shields.io/badge/Zigmod-latest-f7a41d)](https://github.com/nektro/zigmod) HTTP handler functions to allow you to easily add OAuth2 login support to your Zig application. diff --git a/oauth2.zig b/oauth2.zig index 1fd71091ec389902e9590d2cad2b8f324273f8fe..3f0787793ba96b6462eb640825d84e9b60ad21e2 100644 --- a/oauth2.zig +++ b/oauth2.zig @@ -313,9 +313,9 @@ pub fn Handlers(comptime T: type) type { try params.append("state", "none"); const req_body = try params.encode(); - var req = try http_client.open(.POST, try std.Uri.parse(client.provider.token_url), .{ - .server_header_buffer = &buf, + var req = try http_client.request(.POST, try std.Uri.parse(client.provider.token_url), .{ .headers = .{ + .accept_encoding = .{ .override = "identity" }, .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Basic {s}", .{try extras.base64EncodeAlloc(alloc, try std.mem.join(alloc, ":", &.{ client.id, client.secret }))}) }, .content_type = .{ .override = "application/x-www-form-urlencoded" }, }, @@ -325,14 +325,11 @@ pub fn Handlers(comptime T: type) type { .redirect_behavior = .not_allowed, }); defer req.deinit(); - req.transfer_encoding = .{ .content_length = req_body.len }; - try req.send(); - try req.writer().writeAll(req_body); - try req.finish(); - try req.wait(); - const body_content = try req.reader().readAllAlloc(alloc, 1024 * 1024 * 5); - if (req.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req.response.status), body_content }); - if (req.response.status != .ok) return error.OauthBadToken; + try req.sendBodyComplete(req_body); + var resp = try req.receiveHead(&.{}); + const body_content = try resp.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5)); + if (resp.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp.head.status), body_content }); + if (resp.head.status != .ok) return error.OauthBadToken; const val = try json.parseFromSlice(alloc, "body.json", body_content, .{ .maximum_depth = 100, .support_trailing_commas = true }); val.acquire(); const tt = val.root.object().getS("token_type").?; @@ -340,9 +337,9 @@ pub fn Handlers(comptime T: type) type { const at = val.root.object().getS("access_token") orelse return try fail(response_status, body_writer, "Identity Provider Login Error!\n{s}", .{body_content}); val.release(); - var req2 = try http_client.open(.GET, try std.Uri.parse(client.provider.me_url), .{ - .server_header_buffer = &buf, + var req2 = try http_client.request(.GET, try std.Uri.parse(client.provider.me_url), .{ .headers = .{ + .accept_encoding = .{ .override = "identity" }, .authorization = .{ .override = try nio.fmt.allocPrint(alloc, "Bearer {s}", .{at}) }, }, .extra_headers = &.{ @@ -351,12 +348,11 @@ pub fn Handlers(comptime T: type) type { .redirect_behavior = .not_allowed, }); defer req2.deinit(); - try req2.send(); - try req2.finish(); - try req2.wait(); - const body_content2 = try req2.reader().readAllAlloc(alloc, 1024 * 1024 * 5); - if (req2.response.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(req2.response.status), body_content2 }); - if (req2.response.status != .ok) return error.OauthBadUserinfo; + try req2.sendBodiless(); + var resp2 = try req2.receiveHead(&.{}); + const body_content2 = try resp2.reader(&buf).allocRemaining(alloc, .limited(1024 * 1024 * 5)); + if (resp2.head.status != .ok) std.log.scoped(.oauth).debug("{s}: {s}", .{ @tagName(resp2.head.status), body_content2 }); + if (resp2.head.status != .ok) return error.OauthBadUserinfo; const val2 = try json.parseFromSlice(alloc, "body2.json", body_content2, .{ .maximum_depth = 100, .support_trailing_commas = true }); val2.acquire(); const id = try fixId(val2.root.object().getAny(client.provider.id_prop).?); -- 2.54.0