Lightpanda: the headless browser designed for AI and automation
stored drained body so that reads keep returning it
Karl Seguinca09c6047cdd
diff --git a/src/browser/tests/net/request.html b/src/browser/tests/net/request.htmlindex e9f8c3756..84d41214b 100644--- a/src/browser/tests/net/request.html+++ b/src/browser/tests/net/request.html@@ -642,3 +642,17 @@const r2 = new Request('https://example.com', { method: 'POST', body: closed, duplex: 'half' });testing.expectTrue(r2.body === closed)</script>++<script id=request_body_stream_after_consume type=module>+ const state = await testing.async();+ const s = new ReadableStream({ start(c) { c.enqueue(new TextEncoder().encode('x')); c.close(); } });+ const r = new Request('https://example.com', { method: 'POST', body: s, duplex: 'half' });+ const text = await r.text();+ state.resolve();+ await state.done(() => {+ testing.expectEqual('x', text);+ testing.expectTrue(r.body === s);+ testing.expectTrue(s.locked);+ testing.expectTrue(r.bodyUsed);+ });+</script>diff --git a/src/browser/webapi/net/Request.zig b/src/browser/webapi/net/Request.zigindex 63f4385d7..6da40397e 100644--- a/src/browser/webapi/net/Request.zig+++ b/src/browser/webapi/net/Request.zig@@ -335,6 +335,10 @@ pub fn bodyBytes(self: *Request) !?[]const u8 {} else if (self._body_stream) |stream| {self._body = try stream.collectBodyBytes(self._arena.allocator());self._body_stream = null;+ // `body` keeps returning the original stream once it's drained.+ if (self._body_view == null) {+ self._body_view = stream;+ }return self._body;} else return null;}