aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-12 05:55:23 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-12 05:55:23 -0800
commite97934a225d814de4d97c7f12c57d7b938631a3e (patch)
treeaae0282d62f71af7b73bbab524b9ff5500cb2c9f
parente65c82a032430fbac651c473bcdb7294113466a5 (diff)
downloadbun-e97934a225d814de4d97c7f12c57d7b938631a3e.tar.gz
bun-e97934a225d814de4d97c7f12c57d7b938631a3e.tar.zst
bun-e97934a225d814de4d97c7f12c57d7b938631a3e.zip
Expose `Response.prototype.headers` and `Response.prototype.clone`
-rw-r--r--src/javascript/jsc/webcore/response.zig32
1 files changed, 32 insertions, 0 deletions
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index a22ad98f0..f05da9af7 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -59,6 +59,11 @@ pub const Response = struct {
.rfn = getArrayBuffer,
.ts = d.ts{},
},
+
+ .@"clone" = .{
+ .rfn = doClone,
+ .ts = d.ts{},
+ },
},
.{
.@"url" = .{
@@ -78,6 +83,10 @@ pub const Response = struct {
.@"get" = getStatusText,
.ro = true,
},
+ .@"headers" = .{
+ .@"get" = getHeaders,
+ .ro = true,
+ },
},
);
@@ -209,6 +218,7 @@ pub const Response = struct {
this.cloneInto(new_response, allocator);
return new_response;
}
+
pub fn getText(
this: *Response,
ctx: js.JSContextRef,
@@ -217,6 +227,7 @@ pub const Response = struct {
_: []const js.JSValueRef,
_: js.ExceptionRef,
) js.JSValueRef {
+
// https://developer.mozilla.org/en-US/docs/Web/API/Response/text
defer this.body.value = .Empty;
return JSPromise.resolvedPromiseValue(
@@ -260,6 +271,7 @@ pub const Response = struct {
.ArrayBuffer => |buffer| {
break :brk ZigString.init(buffer.ptr[buffer.offset..buffer.byte_len]).toValue(ctx.ptr());
},
+ else => unreachable,
}
}),
).asRef();
@@ -315,6 +327,7 @@ pub const Response = struct {
zig_string = ZigString.init(buffer.ptr[buffer.offset..buffer.byte_len]);
break :brk zig_string.toJSStringRef();
},
+ else => unreachable,
}
},
) orelse {
@@ -388,6 +401,7 @@ pub const Response = struct {
exception,
);
},
+ else => unreachable,
}
}),
),
@@ -1662,16 +1676,26 @@ pub const Body = struct {
return result;
}
};
+
+ pub const PendingValue = struct {
+ promise: ?JSValue = null,
+ global: *JSGlobalObject,
+ task: ?*anyopaque = null,
+ };
+
pub const Value = union(Tag) {
ArrayBuffer: ArrayBuffer,
String: string,
Empty: u0,
Unconsumed: u0,
+ Locked: PendingValue,
+
pub const Tag = enum {
ArrayBuffer,
String,
Empty,
Unconsumed,
+ Locked,
};
pub fn length(value: *const Value) usize {
@@ -1696,6 +1720,13 @@ pub const Body = struct {
}, .value = .{ .Empty = 0 } };
}
+ pub fn @"200"(_: js.JSContextRef) Body {
+ return Body{ .init = Init{
+ .headers = null,
+ .status_code = 200,
+ }, .value = .{ .Empty = 0 } };
+ }
+
pub fn extract(ctx: js.JSContextRef, body_ref: js.JSObjectRef, exception: js.ExceptionRef) Body {
return extractBody(
ctx,
@@ -1751,6 +1782,7 @@ pub const Body = struct {
body.value = Value{
.String = std.fmt.allocPrint(default_allocator, "{}", .{zig_str}) catch unreachable,
};
+ body.ptr_allocator = default_allocator;
// body.ptr = body.
// body.len = body.value.String.len;str.characters8()[0..len] };