支持flutter调用

This commit is contained in:
2025-01-15 09:55:42 +08:00
parent 234d8ea7ca
commit 0fee2d7f69
7 changed files with 88 additions and 17 deletions

View File

@@ -187,7 +187,7 @@ class ShelfWebServer implements WebServer {
// print("method: ${m.reflectee.method} $p");
//把地址加入路由
addRouter(m.reflectee.method, p, (req, [a, b, c, d, e, f]) {
addRouter(m.reflectee.method, p, (req, [a, b, c, d, e, f]) async {
//从request中获取token并解码传入
String? token = req.headers["token"];
dynamic payload;
@@ -205,7 +205,19 @@ class ShelfWebServer implements WebServer {
} else {
args = [req];
}
return im.invoke(v.simpleName, args).reflectee;
Response response = await im.invoke(v.simpleName, args).reflectee as Response;
//判断contenttype是否定义
var t = response.headers["content-type"];
if (t == null) {
//设置默认contenttype
response = response.change(headers: {
...response.headers,
"content-type": m.reflectee.responseType.type
});
}
return response;
});
}
}