From 5a0736cf2a9f8a50590e188d3392a7020bc6e1ae Mon Sep 17 00:00:00 2001 From: Luna Date: Sat, 10 Apr 2021 15:12:17 -0300 Subject: [PATCH] multipart: create full boundary value --- src/main.zig | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main.zig b/src/main.zig index ec281c0..7a05277 100644 --- a/src/main.zig +++ b/src/main.zig @@ -67,24 +67,31 @@ const Multipart = struct { const Self = @This(); - pub fn init(body: []const u8, content_type: []const u8) !Multipart { + // TODO: move boundary_buffer to allocator + pub fn init(body: []const u8, content_type: []const u8, boundary_buffer: []u8) !Multipart { // parse content_type into what we want (the boundary) var it = std.mem.split(content_type, ";"); const should_be_multipart = it.next() orelse return error.MissingContentType; + std.log.debug("should be multipart: {s}", .{should_be_multipart}); if (!std.mem.eql(u8, should_be_multipart, "multipart/form-data")) return error.InvalidContentType; const should_be_boundary = it.next() orelse return error.MissingBoundary; + std.log.debug("should be boundary: {s} {d}", .{ should_be_boundary, should_be_boundary.len }); if (!std.mem.startsWith(u8, should_be_boundary, " boundary=")) return error.InvalidBoundary; var boundary_it = std.mem.split(should_be_boundary, "="); _ = boundary_it.next(); const boundary_value = boundary_it.next() orelse return error.InvalidBoundary; + std.log.debug("boundary value: {s} {d}", .{ boundary_value, boundary_value.len }); + + const actual_boundary_value = try std.fmt.bufPrint(boundary_buffer, "--{s}", .{boundary_value}); + std.log.debug("actual boundary value: {s} {d}", .{ actual_boundary_value, actual_boundary_value.len }); return Self{ .stream = StreamT{ .buffer = body, .pos = 0 }, - .boundary = boundary_value, + .boundary = actual_boundary_value, }; }