koa使用ctx.set设置transfer-encoding为chunked之后,客户端接受不到ctx.body的返回值,烦请各位解答一下,谢谢🙏
简化代码如下:
app.use(async (ctx) => {
if (ctx.request.path === '/') {
ctx.set('transfer-encoding', 'chunked');
return ctx.body = '123';
}
});
使用postman测试:
koa使用ctx.set设置transfer-encoding为chunked之后,客户端接受不到ctx.body的返回值,烦请各位解答一下,谢谢🙏
简化代码如下:
app.use(async (ctx) => {
if (ctx.request.path === '/') {
ctx.set('transfer-encoding', 'chunked');
return ctx.body = '123';
}
});
使用postman测试:
10 回答11.1k 阅读
6 回答3k 阅读
5 回答4.8k 阅读✓ 已解决
4 回答3.1k 阅读✓ 已解决
2 回答2.6k 阅读✓ 已解决
4 回答2.4k 阅读✓ 已解决
3 回答2.3k 阅读✓ 已解决
试了一下, 发现应该是 koa 自动带上了 content-length 导致的.
在chrome中, 不会发生解析失败的问题, 但是在 postman 客户端, 和 node http 模块 get 时, 会发生解析错误.
试了一下, 在 koa 源码, response 文件中,
临时改成了
然后再运行问题中的代码, 用 postman 或者 nodejs http.get 测试, 都能正常返回.
至于, 为什么 koa 要自动带上 content-length 不做判断, 和如何解决这种情况或者说有没有必要解决...希望有知道的大佬补充一下orz