Skip to content

Commit dcb437b

Browse files
committed
[bun.js] Response.prototype.type
1 parent 1be9e3c commit dcb437b

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

src/javascript/jsc/webcore/response.zig

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,10 @@ pub const Response = struct {
102102
.@"get" = getBodyUsed,
103103
.ro = true,
104104
},
105+
.@"type" = .{
106+
.@"get" = getResponseType,
107+
.ro = true,
108+
},
105109
},
106110
);
107111

@@ -169,6 +173,20 @@ pub const Response = struct {
169173
return ZigString.init(this.url).withEncoding().toValueGC(ctx.ptr()).asObjectRef();
170174
}
171175

176+
pub fn getResponseType(
177+
this: *Response,
178+
ctx: js.JSContextRef,
179+
_: js.JSValueRef,
180+
_: js.JSStringRef,
181+
_: js.ExceptionRef,
182+
) js.JSValueRef {
183+
if (this.body.init.status_code < 200) {
184+
return ZigString.init("error").toValue(ctx.ptr()).asObjectRef();
185+
}
186+
187+
return ZigString.init("basic").toValue(ctx.ptr()).asObjectRef();
188+
}
189+
172190
pub fn getBodyUsed(
173191
this: *Response,
174192
_: js.JSContextRef,

0 commit comments

Comments
 (0)