aboutsummaryrefslogtreecommitdiff
path: root/src/bun.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/bun.js')
-rw-r--r--src/bun.js/api/server.zig23
-rw-r--r--src/bun.js/bindings/bindings.cpp2
-rw-r--r--src/bun.js/bindings/bindings.zig1
-rw-r--r--src/bun.js/webcore/response.zig31
4 files changed, 29 insertions, 28 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index 0e39a23f2..65c85adcf 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -1961,10 +1961,9 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// uWS automatically adds the status line if needed
// we want to batch network calls as much as possible
- if (!(this.response_ptr.?.statusCode() == 200 and this.response_ptr.?.body.init.headers == null)) {
- this.renderMetadata();
- }
-
+ // if (!(this.response_ptr.?.statusCode() == 200 and this.response_ptr.?.body.init.headers == null)) {
+ // }
+ this.renderMetadata();
stream.value.ensureStillAlive();
var response_stream = this.allocator.create(ResponseStream.JSSink) catch unreachable;
@@ -2090,22 +2089,6 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
stream.value.ensureStillAlive();
- // This is commented out for now because new ReadableStream({ type: 'direct' })
- // that doesn't write immediately will cause the request to exit early.
-
- // const is_in_progress = response_stream.sink.has_backpressure or !(response_stream.sink.wrote == 0 and
- // response_stream.sink.buffer.len == 0);
-
- // if (!stream.isLocked(this.server.globalThis) and !is_in_progress) {
- // if (JSC.WebCore.ReadableStream.fromJS(stream.value, this.server.globalThis)) |comparator| {
- // if (std.meta.activeTag(comparator.ptr) == std.meta.activeTag(stream.ptr)) {
- // streamLog("is not locked", .{});
- // this.renderMissing();
- // return;
- // }
- // }
- // }
-
this.setAbortHandler();
streamLog("is in progress, but did not return a Promise", .{});
stream.value.unprotect();
diff --git a/src/bun.js/bindings/bindings.cpp b/src/bun.js/bindings/bindings.cpp
index 7c6d295d0..77b895053 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -3970,7 +3970,7 @@ static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigne
return clientData->builtinNames().redirectPublicName();
}
case BuiltinNamesMap::contentType: {
- return clientData->builtinNames().connectPrivateName();
+ return clientData->builtinNames().contentTypePrivateName();
}
}
}
diff --git a/src/bun.js/bindings/bindings.zig b/src/bun.js/bindings/bindings.zig
index 1c09378a8..13d0f606f 100644
--- a/src/bun.js/bindings/bindings.zig
+++ b/src/bun.js/bindings/bindings.zig
@@ -4188,6 +4188,7 @@ pub const JSValue = enum(JSValueReprInt) {
data,
toString,
redirect,
+ contentType,
};
// intended to be more lightweight than ZigString
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index 0dce5bfa3..25a1a18f0 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -226,8 +226,10 @@ pub const Response = struct {
// EventStream defines "contentType"
const locked = this.body.value.Locked;
if (locked.readable) |readable| {
- if (readable.value.getOptional(locked.global, "contentType", ZigString.Slice) catch null) |slice| {
- this.body.init.headers.?.put("content-type", slice.slice(), globalThis);
+ if (readable.value.fastGetDirect(globalThis, .contentType)) |value| {
+ if (value.isString()) {
+ this.body.init.headers.?.put("content-type", value.getZigString(globalThis).slice(), globalThis);
+ }
}
}
}
@@ -544,24 +546,39 @@ pub const Response = struct {
.url = "",
};
- if (response.body.init.headers != null) {
+ if (response.body.init.headers != null and !response.body.init.headers.?.fastHas(.ContentType)) {
if (response.body.value == .Blob and
- response.body.value.Blob.content_type.len > 0 and
- !response.body.init.headers.?.fastHas(.ContentType))
+ response.body.value.Blob.content_type.len > 0)
{
response.body.init.headers.?.put("content-type", response.body.value.Blob.content_type, globalThis);
} else if (response.body.value == .Locked) {
const locked = response.body.value.Locked;
if (locked.readable) |readable| {
- if (readable.value.fastGetDirect(locked.global, .contentType) catch null) |value| {
+ if (readable.value.fastGetDirect(globalThis, .contentType)) |value| {
if (value.isString()) {
- response.body.init.headers.?.put("content-type", value.toBunString(locked.global).toSlice(), globalThis);
+ response.body.init.headers.?.put("content-type", value.getZigString(globalThis).slice(), globalThis);
}
}
}
}
}
+ // TODO: we should be able to do this without constructing a headers object
+ // but for now this workaround is needed to support the following code snippet
+ // Bun.serve({ fetch() { return new Response(new EventStream()); }})
+ // and the lazy headers do not pick up on this.
+ else if (response.body.init.headers == null and response.body.value == .Locked) {
+ const locked = response.body.value.Locked;
+ if (locked.readable) |readable| {
+ if (readable.value.fastGetDirect(globalThis, .contentType)) |value| {
+ if (value.isString()) {
+ response.body.init.headers = FetchHeaders.createEmpty();
+ response.body.init.headers.?.put("content-type", value.getZigString(globalThis).slice(), globalThis);
+ }
+ }
+ }
+ }
+
return response;
}
};