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.zig10
-rw-r--r--src/bun.js/bindings/bindings.cpp4
-rw-r--r--src/bun.js/webcore/response.zig35
3 files changed, 32 insertions, 17 deletions
diff --git a/src/bun.js/api/server.zig b/src/bun.js/api/server.zig
index e35759245..0e39a23f2 100644
--- a/src/bun.js/api/server.zig
+++ b/src/bun.js/api/server.zig
@@ -1436,16 +1436,13 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// this request was already finalized
if (this.sink) |wrapper| {
wrapper.sink.abort();
- this.markComplete();
- this.deinit();
+ this.finalize();
return;
}
// if we can, free the request now.
if (this.isDeadRequest()) {
- this.finalizeWithoutDeinit();
- this.markComplete();
- this.deinit();
+ this.finalize();
return;
}
@@ -2110,8 +2107,7 @@ fn NewRequestContext(comptime ssl_enabled: bool, comptime debug_mode: bool, comp
// }
this.setAbortHandler();
- streamLog("is in progress, but did not return a Promise. Finalizing request context", .{});
- this.finalizeWithoutDeinit();
+ 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 be3408555..7c6d295d0 100644
--- a/src/bun.js/bindings/bindings.cpp
+++ b/src/bun.js/bindings/bindings.cpp
@@ -3937,6 +3937,7 @@ enum class BuiltinNamesMap : uint8_t {
data,
toString,
redirect,
+ contentType
};
static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigned char name)
@@ -3968,6 +3969,9 @@ static JSC::Identifier builtinNameMap(JSC::JSGlobalObject* globalObject, unsigne
case BuiltinNamesMap::redirect: {
return clientData->builtinNames().redirectPublicName();
}
+ case BuiltinNamesMap::contentType: {
+ return clientData->builtinNames().connectPrivateName();
+ }
}
}
diff --git a/src/bun.js/webcore/response.zig b/src/bun.js/webcore/response.zig
index b4ea08579..0dce5bfa3 100644
--- a/src/bun.js/webcore/response.zig
+++ b/src/bun.js/webcore/response.zig
@@ -222,6 +222,14 @@ pub const Response = struct {
if (content_type.len > 0) {
this.body.init.headers.?.put("content-type", content_type, globalThis);
}
+ } else if (this.body.value == .Locked) {
+ // 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);
+ }
+ }
}
}
@@ -536,12 +544,22 @@ pub const Response = struct {
.url = "",
};
- if (response.body.value == .Blob and
- response.body.init.headers != null and
- response.body.value.Blob.content_type.len > 0 and
- !response.body.init.headers.?.fastHas(.ContentType))
- {
- response.body.init.headers.?.put("content-type", response.body.value.Blob.content_type, globalThis);
+ if (response.body.init.headers != null) {
+ if (response.body.value == .Blob and
+ response.body.value.Blob.content_type.len > 0 and
+ !response.body.init.headers.?.fastHas(.ContentType))
+ {
+ 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 (value.isString()) {
+ response.body.init.headers.?.put("content-type", value.toBunString(locked.global).toSlice(), globalThis);
+ }
+ }
+ }
+ }
}
return response;
@@ -1725,14 +1743,11 @@ pub const FetchEvent = struct {
if (strings.eqlComptime(name, "content-length")) {
content_length = std.fmt.parseInt(usize, headers.asStr(header.value), 10) catch null;
- continue;
}
// Some headers need to be managed by bun
if (strings.eqlComptime(name, "transfer-encoding") or
- strings.eqlComptime(name, "content-encoding") or
- strings.eqlComptime(name, "strict-transport-security") or
- strings.eqlComptime(name, "content-security-policy"))
+ strings.eqlComptime(name, "content-encoding"))
{
continue;
}