switch to http status enum
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 8m10s
All checks were successful
AWS-Zig Build / build-zig-amd64-host (push) Successful in 8m10s
This commit is contained in:
parent
c1df6ef3a6
commit
5c7aed071f
4 changed files with 8 additions and 8 deletions
|
|
@ -645,7 +645,7 @@ fn generateOperation(allocator: std.mem.Allocator, operation: smithy.ShapeInfo,
|
||||||
try outputIndent(child_state, writer);
|
try outputIndent(child_state, writer);
|
||||||
try writer.print(".uri = \"{s}\",\n", .{trait.http.uri});
|
try writer.print(".uri = \"{s}\",\n", .{trait.http.uri});
|
||||||
try outputIndent(child_state, writer);
|
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 outputIndent(state, writer);
|
||||||
_ = try writer.write("};\n\n");
|
_ = try writer.write("};\n\n");
|
||||||
}
|
}
|
||||||
|
|
|
||||||
10
src/aws.zig
10
src/aws.zig
|
|
@ -82,7 +82,7 @@ const log = struct {
|
||||||
pub const Options = struct {
|
pub const Options = struct {
|
||||||
region: []const u8 = "aws-global",
|
region: []const u8 = "aws-global",
|
||||||
dualstack: bool = false,
|
dualstack: bool = false,
|
||||||
success_http_code: i64 = 200,
|
success_http_status: std.http.Status = .ok,
|
||||||
client: Client,
|
client: Client,
|
||||||
credential_options: credentials.Options = .{},
|
credential_options: credentials.Options = .{},
|
||||||
|
|
||||||
|
|
@ -92,7 +92,7 @@ pub const Options = struct {
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Diagnostics = struct {
|
pub const Diagnostics = struct {
|
||||||
http_code: i64,
|
response_status: std.http.Status,
|
||||||
response_body: []const u8,
|
response_body: []const u8,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
||||||
|
|
@ -305,7 +305,7 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rest_options = options;
|
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);
|
return try Self.callAws(aws_request, rest_options);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -416,14 +416,14 @@ pub fn Request(comptime request_action: anytype) type {
|
||||||
);
|
);
|
||||||
defer response.deinit();
|
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
|
// If the consumer prrovided diagnostics, they are likely handling
|
||||||
// this error themselves. We'll not spam them with log.err
|
// this error themselves. We'll not spam them with log.err
|
||||||
// output. Note that we may need to add additional information
|
// output. Note that we may need to add additional information
|
||||||
// in diagnostics, as reportTraffic provides more information
|
// in diagnostics, as reportTraffic provides more information
|
||||||
// than what exists in the diagnostics data
|
// than what exists in the diagnostics data
|
||||||
if (options.diagnostics) |d| {
|
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);
|
d.response_body = try d.allocator.dupe(u8, response.body);
|
||||||
} else try reportTraffic(
|
} else try reportTraffic(
|
||||||
options.client.allocator,
|
options.client.allocator,
|
||||||
|
|
|
||||||
|
|
@ -363,7 +363,7 @@ pub const AwsHttp = struct {
|
||||||
log.debug("raw response body:\n{s}", .{aw.written()});
|
log.debug("raw response body:\n{s}", .{aw.written()});
|
||||||
|
|
||||||
const rc = HttpResult{
|
const rc = HttpResult{
|
||||||
.response_code = @intFromEnum(response.head.status),
|
.response_code = response.head.status,
|
||||||
.body = try aw.toOwnedSlice(),
|
.body = try aw.toOwnedSlice(),
|
||||||
.headers = try resp_headers.toOwnedSlice(self.allocator),
|
.headers = try resp_headers.toOwnedSlice(self.allocator),
|
||||||
.allocator = self.allocator,
|
.allocator = self.allocator,
|
||||||
|
|
|
||||||
|
|
@ -9,7 +9,7 @@ pub const Request = struct {
|
||||||
headers: []const std.http.Header = &.{},
|
headers: []const std.http.Header = &.{},
|
||||||
};
|
};
|
||||||
pub const Result = struct {
|
pub const Result = struct {
|
||||||
response_code: u16, // actually 3 digits can fit in u10
|
response_code: std.http.Status,
|
||||||
body: []const u8,
|
body: []const u8,
|
||||||
headers: []const std.http.Header,
|
headers: []const std.http.Header,
|
||||||
allocator: std.mem.Allocator,
|
allocator: std.mem.Allocator,
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue