still bad but compiles

This commit is contained in:
Ciro Spaciari
2025-11-11 17:49:25 -08:00
parent 5ffc79e1bb
commit 6bd677f861
3 changed files with 20 additions and 19 deletions

View File

@@ -1371,7 +1371,7 @@ pub fn Bun__fetch_(
body.detach();
} else {
// These are single-use, and have effectively been moved to the FetchTasklet.
body = FetchTasklet.HTTPRequestBody.Empty;
body = HTTPRequestBody.Empty;
}
proxy = null;
url_proxy_buffer = "";

View File

@@ -137,7 +137,7 @@ pub fn updateLifeCycle(this: *FetchTasklet) bun.JSTerminated!void {
// in this case we wanna a jsc.Strong.Optional so we just convert it
var value = this.onReject();
const err = value.toJS(globalThis);
if (this.sink) |sink| {
if (this.request.sink) |sink| {
sink.cancel(err);
}
break :brk value.JSValue;
@@ -288,7 +288,7 @@ pub fn deinit(this: *FetchTasklet) error{}!void {
allocator.destroy(this);
}
fn getAbortError(this: *FetchTasklet) ?Body.Value.ValueError {
pub fn getAbortError(this: *FetchTasklet) ?Body.Value.ValueError {
if (this.abort_reason.has()) {
defer this.clearAbortSignal();
const out = this.abort_reason;
@@ -463,11 +463,11 @@ comptime {
pub fn onResolve(this: *FetchTasklet) JSValue {
log("onResolve", .{});
const response = bun.new(Response, this.response.toResponse());
const response = bun.new(jsc.WebCore.Response, this.response.toResponse());
const response_js = Response.makeMaybePooled(@as(*jsc.JSGlobalObject, this.global_this), response);
response_js.ensureStillAlive();
this.response = jsc.Weak(FetchTasklet).create(response_js, this.global_this, .FetchResponse, this);
this.native_response = response.ref();
this.response.response = jsc.Weak(FetchTasklet).create(response_js, this.global_this, .FetchResponse, this);
this.response.native_response = response.ref();
return response_js;
}

View File

@@ -52,7 +52,7 @@ fn parent(this: *Response) *FetchTasklet {
pub fn onReadableStreamAvailable(ctx: *anyopaque, globalThis: *jsc.JSGlobalObject, readable: jsc.WebCore.ReadableStream) void {
const this = bun.cast(*FetchTasklet, ctx);
this.readable_stream_ref = jsc.WebCore.ReadableStream.Strong.init(readable, globalThis);
this.response.readable_stream_ref = jsc.WebCore.ReadableStream.Strong.init(readable, globalThis);
}
pub fn checkServerIdentity(this: *Response, certificate_info: http.CertificateInfo) bool {
@@ -278,7 +278,7 @@ pub fn onBodyReceived(this: *Response) bun.JSTerminated!void {
pub fn onStartStreamingHTTPResponseBodyCallback(ctx: *anyopaque) jsc.WebCore.DrainResult {
const this = bun.cast(*FetchTasklet, ctx);
if (this.signal_store.aborted.load(.monotonic)) {
if (this.shared.signal_store.aborted.load(.monotonic)) {
return jsc.WebCore.DrainResult{
.aborted = {},
};
@@ -296,12 +296,12 @@ pub fn onStartStreamingHTTPResponseBodyCallback(ctx: *anyopaque) jsc.WebCore.Dra
this.mutex.lock();
defer this.mutex.unlock();
const size_hint = this.getSizeHint();
const size_hint = this.response.getSizeHint();
var scheduled_response_buffer = this.scheduled_response_buffer.list;
var scheduled_response_buffer = this.response.scheduled_response_buffer.list;
// This means we have received part of the body but not the whole thing
if (scheduled_response_buffer.items.len > 0) {
this.scheduled_response_buffer = .{
this.response.scheduled_response_buffer = .{
.allocator = bun.default_allocator,
.list = .{
.items = &.{},
@@ -322,7 +322,7 @@ pub fn onStartStreamingHTTPResponseBodyCallback(ctx: *anyopaque) jsc.WebCore.Dra
};
}
fn getSizeHint(this: *Response) Blob.SizeType {
pub fn getSizeHint(this: *Response) Blob.SizeType {
return switch (this.body_size) {
.content_length => @truncate(this.body_size.content_length),
.total_received => @truncate(this.body_size.total_received),
@@ -331,7 +331,8 @@ fn getSizeHint(this: *Response) Blob.SizeType {
}
fn toBodyValue(this: *Response) Body.Value {
if (this.getAbortError()) |err| {
const tasklet = this.parent();
if (tasklet.getAbortError()) |err| {
return .{ .Error = err };
}
if (this.flags.is_waiting_body) {
@@ -339,9 +340,9 @@ fn toBodyValue(this: *Response) Body.Value {
.Locked = .{
.size_hint = this.getSizeHint(),
.task = this,
.global = this.global_this,
.onStartStreaming = FetchTasklet.onStartStreamingHTTPResponseBodyCallback,
.onReadableStreamAvailable = FetchTasklet.onReadableStreamAvailable,
.global = tasklet.global_this,
.onStartStreaming = onStartStreamingHTTPResponseBodyCallback,
.onReadableStreamAvailable = onReadableStreamAvailable,
},
};
return response;
@@ -387,7 +388,7 @@ pub fn ignoreRemainingResponseBody(this: *Response) void {
this.flags.ignore_data = true;
}
pub fn toResponse(this: *Response) Response {
pub fn toResponse(this: *Response) jsc.WebCore.Response {
log("toResponse", .{});
const tasklet = this.parent();
bun.assert(tasklet.shared.metadata != null);
@@ -395,7 +396,7 @@ pub fn toResponse(this: *Response) Response {
const metadata = tasklet.shared.metadata.?;
const http_response = metadata.response;
this.flags.is_waiting_body = tasklet.shared.result.has_more;
return Response.init(
return jsc.WebCore.Response.init(
.{
.headers = FetchHeaders.createFromPicoHeaders(http_response.headers),
.status_code = @as(u16, @truncate(http_response.status_code)),
@@ -405,7 +406,7 @@ pub fn toResponse(this: *Response) Response {
.value = this.toBodyValue(),
},
bun.String.createAtomIfPossible(metadata.url),
this.result.redirected,
tasklet.shared.result.redirected,
);
}