Skip to content

Commit

Permalink
fix(node:http) fix node:http chunked encoding on server and add chunk…
Browse files Browse the repository at this point in the history
…ed encoding support on the client (#15579)

Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
  • Loading branch information
cirospaciari and Jarred-Sumner authored Dec 5, 2024
1 parent 3a4a9ae commit dd5c40d
Show file tree
Hide file tree
Showing 16 changed files with 1,300 additions and 99 deletions.
3 changes: 2 additions & 1 deletion src/bun.js/bindings/Sink.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@ enum SinkID : uint8_t {
HTMLRewriterSink = 3,
HTTPResponseSink = 4,
HTTPSResponseSink = 5,
FetchTaskletChunkedRequestSink = 6,

};
static constexpr unsigned numberOfSinkIDs
= 7;
= 8;

}
22 changes: 22 additions & 0 deletions src/bun.js/bindings/ZigGlobalObject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3127,6 +3127,12 @@ void GlobalObject::finishCreation(VM& vm)
init.set(prototype);
});

m_JSFetchTaskletChunkedRequestControllerPrototype.initLater(
[](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) {
auto* prototype = createJSSinkControllerPrototype(init.vm, init.owner, WebCore::SinkID::FetchTaskletChunkedRequestSink);
init.set(prototype);
});

m_performanceObject.initLater(
[](const JSC::LazyProperty<JSC::JSGlobalObject, JSC::JSObject>::Initializer& init) {
auto* globalObject = reinterpret_cast<Zig::GlobalObject*>(init.owner);
Expand Down Expand Up @@ -3255,6 +3261,16 @@ void GlobalObject::finishCreation(VM& vm)
init.setConstructor(constructor);
});

m_JSFetchTaskletChunkedRequestSinkClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto* prototype = createJSSinkPrototype(init.vm, init.global, WebCore::SinkID::FetchTaskletChunkedRequestSink);
auto* structure = JSFetchTaskletChunkedRequestSink::createStructure(init.vm, init.global, prototype);
auto* constructor = JSFetchTaskletChunkedRequestSinkConstructor::create(init.vm, init.global, JSFetchTaskletChunkedRequestSinkConstructor::createStructure(init.vm, init.global, init.global->functionPrototype()), jsCast<JSObject*>(prototype));
init.setPrototype(prototype);
init.setStructure(structure);
init.setConstructor(constructor);
});

m_JSBufferClassStructure.initLater(
[](LazyClassStructure::Initializer& init) {
auto prototype = WebCore::createBufferPrototype(init.vm, init.global);
Expand Down Expand Up @@ -3810,6 +3826,8 @@ void GlobalObject::visitChildrenImpl(JSCell* cell, Visitor& visitor)
thisObject->m_JSHTTPResponseSinkClassStructure.visit(visitor);
thisObject->m_JSHTTPSResponseControllerPrototype.visit(visitor);
thisObject->m_JSHTTPSResponseSinkClassStructure.visit(visitor);
thisObject->m_JSFetchTaskletChunkedRequestSinkClassStructure.visit(visitor);
thisObject->m_JSFetchTaskletChunkedRequestControllerPrototype.visit(visitor);
thisObject->m_JSSocketAddressStructure.visit(visitor);
thisObject->m_JSSQLStatementStructure.visit(visitor);
thisObject->m_V8GlobalInternals.visit(visitor);
Expand Down Expand Up @@ -4349,6 +4367,10 @@ GlobalObject::PromiseFunctions GlobalObject::promiseHandlerID(Zig::FFIFunction h
return GlobalObject::PromiseFunctions::Bun__onResolveEntryPointResult;
} else if (handler == Bun__onRejectEntryPointResult) {
return GlobalObject::PromiseFunctions::Bun__onRejectEntryPointResult;
} else if (handler == Bun__FetchTasklet__onResolveRequestStream) {
return GlobalObject::PromiseFunctions::Bun__FetchTasklet__onResolveRequestStream;
} else if (handler == Bun__FetchTasklet__onRejectRequestStream) {
return GlobalObject::PromiseFunctions::Bun__FetchTasklet__onRejectRequestStream;
} else {
RELEASE_ASSERT_NOT_REACHED();
}
Expand Down
12 changes: 11 additions & 1 deletion src/bun.js/bindings/ZigGlobalObject.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,11 @@ class GlobalObject : public Bun::GlobalScope {
JSC::JSValue HTTPSResponseSinkPrototype() const { return m_JSHTTPSResponseSinkClassStructure.prototypeInitializedOnMainThread(this); }
JSC::JSValue JSReadableHTTPSResponseSinkControllerPrototype() const { return m_JSHTTPSResponseControllerPrototype.getInitializedOnMainThread(this); }

JSC::Structure* FetchTaskletChunkedRequestSinkStructure() const { return m_JSFetchTaskletChunkedRequestSinkClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* FetchTaskletChunkedRequestSink() { return m_JSFetchTaskletChunkedRequestSinkClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue FetchTaskletChunkedRequestSinkPrototype() const { return m_JSFetchTaskletChunkedRequestSinkClassStructure.prototypeInitializedOnMainThread(this); }
JSC::JSValue JSReadableFetchTaskletChunkedRequestSinkControllerPrototype() const { return m_JSFetchTaskletChunkedRequestControllerPrototype.getInitializedOnMainThread(this); }

JSC::Structure* JSBufferListStructure() const { return m_JSBufferListClassStructure.getInitializedOnMainThread(this); }
JSC::JSObject* JSBufferList() { return m_JSBufferListClassStructure.constructorInitializedOnMainThread(this); }
JSC::JSValue JSBufferListPrototype() const { return m_JSBufferListClassStructure.prototypeInitializedOnMainThread(this); }
Expand Down Expand Up @@ -329,8 +334,10 @@ class GlobalObject : public Bun::GlobalScope {
Bun__BodyValueBufferer__onResolveStream,
Bun__onResolveEntryPointResult,
Bun__onRejectEntryPointResult,
Bun__FetchTasklet__onRejectRequestStream,
Bun__FetchTasklet__onResolveRequestStream,
};
static constexpr size_t promiseFunctionsSize = 24;
static constexpr size_t promiseFunctionsSize = 26;

static PromiseFunctions promiseHandlerID(SYSV_ABI EncodedJSValue (*handler)(JSC__JSGlobalObject* arg0, JSC__CallFrame* arg1));

Expand Down Expand Up @@ -504,6 +511,8 @@ class GlobalObject : public Bun::GlobalScope {
LazyClassStructure m_JSFileSinkClassStructure;
LazyClassStructure m_JSHTTPResponseSinkClassStructure;
LazyClassStructure m_JSHTTPSResponseSinkClassStructure;
LazyClassStructure m_JSFetchTaskletChunkedRequestSinkClassStructure;

LazyClassStructure m_JSStringDecoderClassStructure;
LazyClassStructure m_NapiClassStructure;
LazyClassStructure m_callSiteStructure;
Expand Down Expand Up @@ -533,6 +542,7 @@ class GlobalObject : public Bun::GlobalScope {
LazyProperty<JSGlobalObject, JSMap> m_esmRegistryMap;
LazyProperty<JSGlobalObject, JSObject> m_JSArrayBufferControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_JSHTTPSResponseControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_JSFetchTaskletChunkedRequestControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_JSFileSinkControllerPrototype;
LazyProperty<JSGlobalObject, JSObject> m_subtleCryptoObject;
LazyProperty<JSGlobalObject, Structure> m_JSHTTPResponseController;
Expand Down
2 changes: 2 additions & 0 deletions src/bun.js/bindings/exports.zig
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ pub const JSArrayBufferSink = JSC.WebCore.ArrayBufferSink.JSSink;
pub const JSHTTPSResponseSink = JSC.WebCore.HTTPSResponseSink.JSSink;
pub const JSHTTPResponseSink = JSC.WebCore.HTTPResponseSink.JSSink;
pub const JSFileSink = JSC.WebCore.FileSink.JSSink;
pub const JSFetchTaskletChunkedRequestSink = JSC.WebCore.FetchTaskletChunkedRequestSink.JSSink;

// WebSocket
pub const WebSocketHTTPClient = @import("../../http/websocket_http_client.zig").WebSocketHTTPClient;
Expand Down Expand Up @@ -962,6 +963,7 @@ comptime {
JSArrayBufferSink.shim.ref();
JSHTTPResponseSink.shim.ref();
JSHTTPSResponseSink.shim.ref();
JSFetchTaskletChunkedRequestSink.shim.ref();
JSFileSink.shim.ref();
JSFileSink.shim.ref();
_ = ZigString__free;
Expand Down
30 changes: 23 additions & 7 deletions src/bun.js/bindings/headers.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 7 additions & 0 deletions src/bun.js/bindings/headers.zig

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 12 additions & 0 deletions src/bun.js/webcore/body.zig
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,18 @@ pub const Body = struct {

return false;
}

pub fn isDisturbed2(this: *const PendingValue, globalObject: *JSC.JSGlobalObject) bool {
if (this.promise != null) {
return true;
}

if (this.readable.get()) |readable| {
return readable.isDisturbed(globalObject);
}

return false;
}
pub fn isStreamingOrBuffering(this: *PendingValue) bool {
return this.readable.held.has() or (this.promise != null and !this.promise.?.isEmptyOrUndefinedOrNull());
}
Expand Down
Loading

0 comments on commit dd5c40d

Please sign in to comment.