dart - 在 dart http 服务器中检测客户端断开连接
问题描述
我使用 dart http 服务器作为模拟服务器来测试我的颤振应用程序与真实服务器的交互,我正在做这样的事情:
final _server = await HttpServer.bind(InternetAddress.anyIPv4, 0);
_server.listen(handleRequest, onError: (error) {
print("onError");
}, onDone: () {
print("Closed");
});
我的一个测试用例包括用户取消一个长时间运行的请求。我想测试请求是否真的被取消并且连接是否关闭。
所以我需要一种方法来在服务器端检测请求是否被取消:
void handleRequest(HttpRequest request) async {
// This future is finished, when the test decides, that the client should have canceled the request
await waitFuture;
request.response
..statusCode
..close():
// How do I know here if the client has canceled the request in the meantime?
不幸的是,服务器似乎只是忽略了任何客户端断开连接。
所以我的问题是:有没有一种方法可以使用飞镖 HTTP 服务器检测客户端断开连接?
解决方案
推荐阅读
- javascript - 如何在 React 中使用 i18n-iso-countries?
- javascript - 滚动。修复滚动部分的时间:最后很慢
- vue.js - 如何使用 vuex(非父/子组件)在不同的组件上运行函数
- java - 如何将两个二维数组“粘贴”在一起?
- visual-studio - Visual Studio:项目名称中的程序集名称和默认命名空间
- swift - 在 Xcode11 中导入 Swift 包
- simulink - 如何实现修改后的传递函数?
- react-native - 是否使用 useState 反应原生动画 => new Animated.Value()?
- vba - DASL 添加列 PR_ENTRYID
- dart - 如何在 Angular Dart 中构建 HttpInterceptor 服务?