mirror of
https://github.com/oven-sh/bun
synced 2026-02-11 03:18:53 +00:00
[bun.js] Response.prototype.type
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user