multipart: add body reading
This commit is contained in:
parent
b4b51a3e05
commit
1a3c1e354f
1 changed files with 17 additions and 0 deletions
17
src/main.zig
17
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,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
|
Loading…
Reference in a new issue