Fix final chunk

This commit is contained in:
jaina heartles 2022-12-09 03:37:46 -08:00
parent 466a15f3cb
commit a035b08f83

View file

@ -71,10 +71,6 @@ fn writeChunk(writer: anytype, contents: []const u8) @TypeOf(writer).Error!void
try writer.writeAll("\r\n"); try writer.writeAll("\r\n");
} }
fn writeLastChunk(writer: anytype) writer.Error!void {
try writer.writeAll("0\r\n");
}
pub fn ResponseStream(comptime BaseWriter: type) type { pub fn ResponseStream(comptime BaseWriter: type) type {
return struct { return struct {
const Self = @This(); const Self = @This();
@ -99,6 +95,7 @@ pub fn ResponseStream(comptime BaseWriter: type) type {
} }
fn flushChunk(self: *Self) Error!void { fn flushChunk(self: *Self) Error!void {
std.log.debug("flushing chunk {}", .{self.buffer_pos});
try writeChunk(self.base_writer, self.buffer[0..self.buffer_pos]); try writeChunk(self.base_writer, self.buffer[0..self.buffer_pos]);
self.buffer_pos = 0; self.buffer_pos = 0;
} }
@ -156,7 +153,7 @@ pub fn ResponseStream(comptime BaseWriter: type) type {
if (self.buffer_pos != 0) { if (self.buffer_pos != 0) {
try self.flushChunk(); try self.flushChunk();
} }
try self.base_writer.writeAll("0\r\n"); try self.base_writer.writeAll("0\r\n\r\n");
} }
} }