From 316a388b79df734ffc034acfbb4cb690b440b93a Mon Sep 17 00:00:00 2001 From: Emil Lerch Date: Tue, 29 Aug 2023 12:36:18 -0700 Subject: [PATCH] support chunked encoding (but not streaming really) --- src/aws_http.zig | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/src/aws_http.zig b/src/aws_http.zig index 9f46800..194b8ff 100644 --- a/src/aws_http.zig +++ b/src/aws_http.zig @@ -211,9 +211,16 @@ pub const AwsHttp = struct { content_length = std.fmt.parseInt(usize, h.value, 10) catch 0; } - var response_data = try self.allocator.alloc(u8, content_length); - errdefer self.allocator.free(response_data); - _ = try req.readAll(response_data); + var response_data: []u8 = + if (req.response.transfer_encoding) |_| // the only value here is "chunked" + try req.reader().readAllAlloc(self.allocator, std.math.maxInt(usize)) + else blk: { + // content length + var tmp_data = try self.allocator.alloc(u8, content_length); + errdefer self.allocator.free(tmp_data); + _ = try req.readAll(tmp_data); + break :blk tmp_data; + }; log.debug("raw response body:\n{s}", .{response_data}); const rc = HttpResult{