Commit abd76938cb

Andrew Kelley <andrew@ziglang.org>
2025-08-05 05:27:55
std.Io.Reader: fix appendRemainingUnlimited
Now it avoids mutating `r` unnecessarily, allowing the `ending` Reader to work.
1 parent 9e5048c
Changed files (2)
lib
std
lib/std/http/test.zig
@@ -414,7 +414,8 @@ test "general client/server API coverage" {
             log.info("{f} {t} {s}", .{ request.head.method, request.head.version, request.head.target });
 
             const gpa = std.testing.allocator;
-            const body = try (try request.readerExpectContinue(&.{})).allocRemaining(gpa, .unlimited);
+            const reader = (try request.readerExpectContinue(&.{}));
+            const body = try reader.allocRemaining(gpa, .unlimited);
             defer gpa.free(body);
 
             if (mem.startsWith(u8, request.head.target, "/get")) {
lib/std/Io/Reader.zig
@@ -367,8 +367,11 @@ pub fn appendRemainingUnlimited(
     const buffer_contents = r.buffer[r.seek..r.end];
     try list.ensureUnusedCapacity(gpa, buffer_contents.len + bump);
     list.appendSliceAssumeCapacity(buffer_contents);
-    r.seek = 0;
-    r.end = 0;
+    // If statement protects `ending`.
+    if (r.end != 0) {
+        r.seek = 0;
+        r.end = 0;
+    }
     // From here, we leave `buffer` empty, appending directly to `list`.
     var writer: Writer = .{
         .buffer = undefined,