[bun.js] Response.prototype.type

This commit is contained in:
Jarred Sumner
2022-03-18 20:04:57 -07:00
parent 1be9e3cf2d
commit dcb437b1ad

View File

@@ -102,6 +102,10 @@ pub const Response = struct {
.@"get" = getBodyUsed,
.ro = true,
},
.@"type" = .{
.@"get" = getResponseType,
.ro = true,
},
},
);
@@ -169,6 +173,20 @@ pub const Response = struct {
return ZigString.init(this.url).withEncoding().toValueGC(ctx.ptr()).asObjectRef();
}
pub fn getResponseType(
this: *Response,
ctx: js.JSContextRef,
_: js.JSValueRef,
_: js.JSStringRef,
_: js.ExceptionRef,
) js.JSValueRef {
if (this.body.init.status_code < 200) {
return ZigString.init("error").toValue(ctx.ptr()).asObjectRef();
}
return ZigString.init("basic").toValue(ctx.ptr()).asObjectRef();
}
pub fn getBodyUsed(
this: *Response,
_: js.JSContextRef,