From 5c7aed071f6251d53a1627080a21d604ff58f0a5 Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Wed, 4 Feb 2026 00:37:27 -0800 Subject: [PATCH] switch to http status enum --- codegen/src/main.zig | 2 +- src/aws.zig | 10 +++++----- src/aws_http.zig | 2 +- src/aws_http_base.zig | 2 +- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/codegen/src/main.zig b/codegen/src/main.zig index a8aa1c7..53918bd 100644 --- a/codegen/src/main.zig +++ b/codegen/src/main.zig @@ -645,7 +645,7 @@ fn generateOperation(allocator: std.mem.Allocator, operation: smithy.ShapeInfo, try outputIndent(child_state, writer); try writer.print(".uri = \"{s}\",\n", .{trait.http.uri}); try outputIndent(child_state, writer); - try writer.print(".success_code = {d},\n", .{trait.http.code}); + try writer.print(".success_code = @as(u10, {d}),\n", .{trait.http.code}); try outputIndent(state, writer); _ = try writer.write("};\n\n"); } diff --git a/src/aws.zig b/src/aws.zig index 86e78a4..91854aa 100644 --- a/src/aws.zig +++ b/src/aws.zig @@ -82,7 +82,7 @@ const log = struct { pub const Options = struct { region: []const u8 = "aws-global", dualstack: bool = false, - success_http_code: i64 = 200, + success_http_status: std.http.Status = .ok, client: Client, credential_options: credentials.Options = .{}, @@ -92,7 +92,7 @@ pub const Options = struct { }; pub const Diagnostics = struct { - http_code: i64, + response_status: std.http.Status, response_body: []const u8, allocator: std.mem.Allocator, @@ -305,7 +305,7 @@ pub fn Request(comptime request_action: anytype) type { } var rest_options = options; - rest_options.success_http_code = Action.http_config.success_code; + rest_options.success_http_status = @enumFromInt(Action.http_config.success_code); return try Self.callAws(aws_request, rest_options); } @@ -416,14 +416,14 @@ pub fn Request(comptime request_action: anytype) type { ); defer response.deinit(); - if (response.response_code != options.success_http_code and response.response_code != 404) { + if (response.response_code != options.success_http_status and response.response_code != .not_found) { // If the consumer prrovided diagnostics, they are likely handling // this error themselves. We'll not spam them with log.err // output. Note that we may need to add additional information // in diagnostics, as reportTraffic provides more information // than what exists in the diagnostics data if (options.diagnostics) |d| { - d.http_code = response.response_code; + d.response_status = response.response_code; d.response_body = try d.allocator.dupe(u8, response.body); } else try reportTraffic( options.client.allocator, diff --git a/src/aws_http.zig b/src/aws_http.zig index 89fefb4..33cec29 100644 --- a/src/aws_http.zig +++ b/src/aws_http.zig @@ -363,7 +363,7 @@ pub const AwsHttp = struct { log.debug("raw response body:\n{s}", .{aw.written()}); const rc = HttpResult{ - .response_code = @intFromEnum(response.head.status), + .response_code = response.head.status, .body = try aw.toOwnedSlice(), .headers = try resp_headers.toOwnedSlice(self.allocator), .allocator = self.allocator, diff --git a/src/aws_http_base.zig b/src/aws_http_base.zig index 4a8f8e4..7065c94 100644 --- a/src/aws_http_base.zig +++ b/src/aws_http_base.zig @@ -9,7 +9,7 @@ pub const Request = struct { headers: []const std.http.Header = &.{}, }; pub const Result = struct { - response_code: u16, // actually 3 digits can fit in u10 + response_code: std.http.Status, body: []const u8, headers: []const std.http.Header, allocator: std.mem.Allocator,