aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-12 05:54:56 -0800
committerGravatar Jarred Sumner <jarred@jarredsumner.com> 2022-03-12 05:54:56 -0800
commite65c82a032430fbac651c473bcdb7294113466a5 (patch)
tree2af4dd261bc8920c4ccac84675ed7abc07214ad9
parent6f39b8f57627b62c4db1a8ee69219b41389b2f96 (diff)
downloadbun-e65c82a032430fbac651c473bcdb7294113466a5.tar.gz
bun-e65c82a032430fbac651c473bcdb7294113466a5.tar.zst
bun-e65c82a032430fbac651c473bcdb7294113466a5.zip
Headers.clone
-rw-r--r--src/javascript/jsc/webcore/response.zig37
1 files changed, 37 insertions, 0 deletions
diff --git a/src/javascript/jsc/webcore/response.zig b/src/javascript/jsc/webcore/response.zig
index 0b4bb7a76..a22ad98f0 100644
--- a/src/javascript/jsc/webcore/response.zig
+++ b/src/javascript/jsc/webcore/response.zig
@@ -167,6 +167,43 @@ pub const Response = struct {
return js.JSValueMakeBoolean(ctx, this.isOK());
}
+ pub fn getHeaders(
+ this: *Response,
+ ctx: js.JSContextRef,
+ _: js.JSValueRef,
+ _: js.JSStringRef,
+ _: js.ExceptionRef,
+ ) js.JSValueRef {
+ // https://developer.mozilla.org/en-US/docs/Web/API/Response/ok
+ if (this.body.init.headers == null) {
+ this.body.init.headers = Headers.empty(this.allocator);
+ }
+
+ return Headers.Class.make(ctx, &this.body.init.headers.?);
+ }
+
+ pub fn doClone(
+ this: *Response,
+ ctx: js.JSContextRef,
+ _: js.JSObjectRef,
+ _: js.JSObjectRef,
+ _: []const js.JSValueRef,
+ _: js.ExceptionRef,
+ ) js.JSValueRef {
+ var cloned = this.clone(getAllocator(ctx));
+ return Response.Class.make(ctx, cloned);
+ }
+
+ pub fn cloneInto(this: *const Response, new_response: *Response, allocator: std.mem.Allocator) void {
+ new_response.* = Response{
+ .allocator = allocator,
+ .body = this.body.clone(allocator),
+ .url = allocator.dupe(u8, this.url) catch unreachable,
+ .status_text = allocator.dupe(u8, this.status_text) catch unreachable,
+ .redirected = this.redirected,
+ };
+ }
+
pub fn clone(this: *const Response, allocator: std.mem.Allocator) *Response {
var new_response = allocator.create(Response) catch unreachable;
this.cloneInto(new_response, allocator);