diff --git a/src/main.zig b/src/main.zig index e2c9e40..5fe9a07 100644 --- a/src/main.zig +++ b/src/main.zig @@ -58,6 +58,7 @@ const ContentDisposition = struct { const Part = struct { disposition: ContentDisposition, content_type: []const u8, + body: []const u8, }; const Multipart = struct { @@ -170,9 +171,25 @@ const Multipart = struct { } } + // the rest of the reader until we find a matching boundary is the part body. + // hzzp does not do it for us because it cant find a body encoding + // (content-length, content-encoding) + // + // we can use the fact that we know the reader is FixedBufferStream + // to extract the remaining body, then trim the boundary! + // + // THIS ASSUMES ONLY ONE FILE IS IN THE WIRE. + + const remaining_body = self.stream.buffer[self.stream.pos..self.stream.buffer.len]; + + var end_boundary_buf: [512]u8 = undefined; + const boundary_end_marker = try std.fmt.bufPrint(&end_boundary_buf, "{s}--\r\n", .{self.boundary}); + const actual_body = std.mem.trim(u8, remaining_body, boundary_end_marker); + return Part{ .disposition = content_disposition.?, .content_type = content_type.?, + .body = actual_body, }; } };