add http payload support

This commit is contained in:
Emil Lerch 2022-06-05 18:27:10 -07:00
parent 21b04317bd
commit b428029cc1
Signed by: lobo
GPG Key ID: A7B62D657EF764F8

View File

@ -345,6 +345,26 @@ pub fn Request(comptime action: anytype) type {
var expected_body_field_len = std.meta.fields(action.Response).len; var expected_body_field_len = std.meta.fields(action.Response).len;
if (@hasDecl(action.Response, "http_header")) if (@hasDecl(action.Response, "http_header"))
expected_body_field_len -= std.meta.fields(@TypeOf(action.Response.http_header)).len; expected_body_field_len -= std.meta.fields(@TypeOf(action.Response.http_header)).len;
if (@hasDecl(action.Response, "http_payload")) {
var rc = FullResponseType{
.response = .{},
.response_metadata = .{
.request_id = try requestIdFromHeaders(aws_request, response, options),
},
.parser_options = .{ .json = .{} },
.raw_parsed = .{ .raw = .{} },
.allocator = options.client.allocator,
};
var body_field = @field(rc.response, action.Response.http_payload);
const BodyField = @TypeOf(body_field);
if (BodyField == []const u8 or BodyField == ?[]const u8) {
expected_body_field_len = 0;
// We can't use body_field for this set - only @field will work
@field(rc.response, action.Response.http_payload) = try options.client.allocator.dupe(u8, response.body);
return rc;
}
rc.deinit();
}
// We don't care about the body if there are no fields we expect there... // We don't care about the body if there are no fields we expect there...
if (std.meta.fields(action.Response).len == 0 or expected_body_field_len == 0) { if (std.meta.fields(action.Response).len == 0 or expected_body_field_len == 0) {
@ -845,6 +865,17 @@ fn FullResponse(comptime action: anytype) type {
} }
} }
} }
if (@hasDecl(Response, "http_payload")) {
var body_field = @field(self.response, Response.http_payload);
const BodyField = @TypeOf(body_field);
if (BodyField == []const u8) {
self.allocator.free(body_field);
}
if (BodyField == ?[]const u8) {
if (body_field) |f|
self.allocator.free(f);
}
}
} }
}; };
} }