Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 15 additions & 15 deletions src/bun.js/api/server.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1186,7 +1186,7 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
}
}

existing_request = Request.init(
existing_request = Request.init2(
bun.String.cloneUTF8(url.href),
headers,
bun.handleOom(this.vm.initRequestBodyValue(body)),
Expand Down Expand Up @@ -2213,13 +2213,13 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
ctx.signal = signal;
signal.pendingActivityRef();

const request_object = Request.new(.{
.method = ctx.method,
.request_context = AnyRequestContext.init(ctx),
.https = ssl_enabled,
.signal = signal.ref(),
.body = body.ref(),
});
const request_object = Request.new(Request.init(
ctx.method,
AnyRequestContext.init(ctx),
ssl_enabled,
signal.ref(),
body.ref(),
));
ctx.request_weakref = .initRef(request_object);

if (comptime debug_mode) {
Expand Down Expand Up @@ -2314,13 +2314,13 @@ pub fn NewServer(protocol_enum: enum { http, https }, development_kind: enum { d
var signal = jsc.WebCore.AbortSignal.new(this.globalThis);
ctx.signal = signal;

var request_object = Request.new(.{
.method = ctx.method,
.request_context = AnyRequestContext.init(ctx),
.https = ssl_enabled,
.signal = signal.ref(),
.body = body.ref(),
});
var request_object = Request.new(Request.init(
ctx.method,
AnyRequestContext.init(ctx),
ssl_enabled,
signal.ref(),
body.ref(),
));
ctx.upgrade_context = upgrade_ctx;
ctx.request_weakref = .initRef(request_object);
// We keep the Request object alive for the duration of the request so that we can remove the pointer to the UWS request object.
Expand Down
5 changes: 3 additions & 2 deletions src/bun.js/node/types.zig
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,10 @@ pub const BlobOrStringOrBuffer = union(enum) {
}
if (allow_request_response) {
if (value.as(jsc.WebCore.Request)) |request| {
request.body.value.toBlobIfPossible();
const bodyValue = request.getBodyValue();
bodyValue.toBlobIfPossible();

if (request.body.value.tryUseAsAnyBlob()) |any_blob_| {
if (bodyValue.tryUseAsAnyBlob()) |any_blob_| {
var any_blob = any_blob_;
defer any_blob.detach();
return .{ .blob = any_blob.toBlob(global) };
Expand Down
15 changes: 8 additions & 7 deletions src/bun.js/webcore/Blob.zig
Original file line number Diff line number Diff line change
Expand Up @@ -1402,28 +1402,29 @@ pub fn writeFileInternal(globalThis: *jsc.JSGlobalObject, path_or_blob_: *PathOr
}

if (data.as(Request)) |request| {
switch (request.body.value) {
const bodyValue = request.getBodyValue();
switch (bodyValue.*) {
.WTFStringImpl,
.InternalBlob,
.Used,
.Empty,
.Blob,
.Null,
=> {
break :brk request.body.value.use();
break :brk bodyValue.use();
},
.Error => |*err_ref| {
destination_blob.detach();
_ = request.body.value.use();
_ = bodyValue.use();
return jsc.JSPromise.dangerouslyCreateRejectedPromiseValueWithoutNotifyingVM(globalThis, err_ref.toJS(globalThis));
},
.Locked => |locked| {
if (destination_blob.isS3()) {
const s3 = &destination_blob.store.?.data.s3;
var aws_options = try s3.getCredentialsWithOptions(options.extra_options, globalThis);
defer aws_options.deinit();
_ = try request.body.value.toReadableStream(globalThis);
if (locked.readable.get(globalThis)) |readable| {
_ = try bodyValue.toReadableStream(globalThis);
if (request.getBodyReadableStream(globalThis) orelse locked.readable.get(globalThis)) |readable| {
if (readable.isDisturbed(globalThis)) {
destination_blob.detach();
return globalThis.throwInvalidArguments("ReadableStream has already been used", .{});
Expand Down Expand Up @@ -1454,8 +1455,8 @@ pub fn writeFileInternal(globalThis: *jsc.JSGlobalObject, path_or_blob_: *PathOr
.mkdirp_if_not_exists = options.mkdirp_if_not_exists orelse true,
});

request.body.value.Locked.task = task;
request.body.value.Locked.onReceiveValue = WriteFileWaitFromLockedValueTask.thenWrap;
bodyValue.Locked.task = task;
bodyValue.Locked.onReceiveValue = WriteFileWaitFromLockedValueTask.thenWrap;

return task.promise.value();
},
Expand Down
24 changes: 12 additions & 12 deletions src/bun.js/webcore/Body.zig
Original file line number Diff line number Diff line change
Expand Up @@ -988,20 +988,20 @@ pub const Value = union(Tag) {
},
};
}
} else {
if (locked.readable.isDisturbed(globalThis)) {
return Value{ .Used = {} };
}
}
if (locked.readable.isDisturbed(globalThis)) {
return Value{ .Used = {} };
}

if (try locked.readable.tee(globalThis)) |readable| {
return Value{
.Locked = .{
.readable = jsc.WebCore.ReadableStream.Strong.init(readable, globalThis),
.global = globalThis,
},
};
}
if (try locked.readable.tee(globalThis)) |readable| {
return Value{
.Locked = .{
.readable = jsc.WebCore.ReadableStream.Strong.init(readable, globalThis),
.global = globalThis,
},
};
}

if (locked.promise != null or locked.action != .none or locked.readable.has()) {
return Value{ .Used = {} };
}
Expand Down
Loading