Skip to content

Commit f2a9562

Browse files
committed
fix: convert response body to proper types before casting
Ensure Bytes, HTML, and Text response bodies are properly converted to their respective types (to_bytes() or to_string()) before casting to JS values to prevent potential type errors.
1 parent 24d9a14 commit f2a9562

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

moon.mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "oboard/mocket",
3-
"version": "0.5.1",
3+
"version": "0.5.2",
44
"deps": {
55
"yj-qin/regexp": "0.3.6",
66
"illusory0x0/native": "0.2.1",

src/mocket.js.mbt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,9 @@ pub fn serve_ffi(mocket : Mocket, port~ : Int) -> Unit {
135135
)
136136
res.end(
137137
match body {
138-
Bytes(b) => @js.Value::cast_from(b)
139-
HTML(s) => @js.Value::cast_from(s)
140-
Text(s) => @js.Value::cast_from(s)
138+
Bytes(b) => @js.Value::cast_from(b.to_bytes())
139+
HTML(s) => @js.Value::cast_from(s.to_string())
140+
Text(s) => @js.Value::cast_from(s.to_string())
141141
Json(j) => @js.Value::cast_from(j.stringify())
142142
Empty => @js.Value::cast_from("")
143143
},

0 commit comments

Comments
 (0)