diff options
author | 2023-02-28 00:11:11 -0800 | |
---|---|---|
committer | 2023-02-28 00:12:32 -0800 | |
commit | 31389b49063a59fa66ab39e595f2ab3339af97c0 (patch) | |
tree | 3cdf93e0e7f0b1cab290f20bd7f437c327e1933e | |
parent | d93d1013a6dce4aabbdd9fb6a12901daeaa51886 (diff) | |
download | bun-31389b49063a59fa66ab39e595f2ab3339af97c0.tar.gz bun-31389b49063a59fa66ab39e595f2ab3339af97c0.tar.zst bun-31389b49063a59fa66ab39e595f2ab3339af97c0.zip |
Make response.body `null` only when user explicitly passes null/undefined
-rw-r--r-- | src/bun.js/webcore/blob.zig | 3 | ||||
-rw-r--r-- | src/bun.js/webcore/request.zig | 13 | ||||
-rw-r--r-- | src/bun.js/webcore/response.zig | 2 | ||||
-rw-r--r-- | test/bun.js/body-stream.test.ts | 2 |
4 files changed, 17 insertions, 3 deletions
diff --git a/src/bun.js/webcore/blob.zig b/src/bun.js/webcore/blob.zig index 9e5ad4ec2..c0a865d5d 100644 --- a/src/bun.js/webcore/blob.zig +++ b/src/bun.js/webcore/blob.zig @@ -435,6 +435,7 @@ pub const Blob = struct { }, // .InlineBlob, .InternalBlob, + .Null, .Empty, .Blob, => { @@ -665,6 +666,7 @@ pub const Blob = struct { .Used, .Empty, .Blob, + .Null, => { break :brk response.body.use(); }, @@ -699,6 +701,7 @@ pub const Blob = struct { .Used, .Empty, .Blob, + .Null, => { break :brk request.body.use(); }, diff --git a/src/bun.js/webcore/request.zig b/src/bun.js/webcore/request.zig index 1a3bc1e4c..67824f4d2 100644 --- a/src/bun.js/webcore/request.zig +++ b/src/bun.js/webcore/request.zig @@ -189,7 +189,7 @@ pub const Request = struct { }, .InternalBlob => return this.body.InternalBlob.contentType(), // .InlineBlob => return this.body.InlineBlob.contentType(), - .Error, .Used, .Locked, .Empty => return MimeType.other.value, + .Null, .Error, .Used, .Locked, .Empty => return MimeType.other.value, } } @@ -395,6 +395,9 @@ pub const Request = struct { return null; }).slice(); request.url_was_allocated = request.url.len > 0; + request.body = .{ + .Null = {}, + }; } else { if (Body.Init.init(getAllocator(globalThis), globalThis, arguments[0], url_or_object_type) catch null) |req_init| { request.headers = req_init.headers; @@ -408,6 +411,10 @@ pub const Request = struct { request.finalizeWithoutDeinit(); return null; } + } else { + request.body = .{ + .Null = {}, + }; } if (urlOrObject.fastGet(globalThis, .url)) |url| { @@ -444,6 +451,10 @@ pub const Request = struct { request.finalizeWithoutDeinit(); return null; } + } else { + request.body = .{ + .Null = {}, + }; } request.url = (arguments[0].toSlice(globalThis, bun.default_allocator).cloneIfNeeded(bun.default_allocator) catch { diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig index 96b7e2409..c3764c16a 100644 --- a/src/bun.js/webcore/response.zig +++ b/src/bun.js/webcore/response.zig @@ -331,7 +331,7 @@ pub const Response = struct { return response.body.value.InternalBlob.contentType(); }, - .Used, .Locked, .Empty, .Error => return default.value, + .Null, .Used, .Locked, .Empty, .Error => return default.value, } } diff --git a/test/bun.js/body-stream.test.ts b/test/bun.js/body-stream.test.ts index 9a68ad3bc..1cd932ed9 100644 --- a/test/bun.js/body-stream.test.ts +++ b/test/bun.js/body-stream.test.ts @@ -3,7 +3,7 @@ import { file, gc, serve, ServeOptions } from "bun"; import { afterAll, afterEach, describe, expect, it, test } from "bun:test"; import { readFileSync } from "fs"; -var port = 4021; +var port = 0; { const BodyMixin = [ |