服务工作者与流连接重置

时间:2018-04-29 02:26:39

标签: service-worker

下面的代码正在执行,但我一直在

  

ERR_CONNECTION_RESET

[(514, 469), (545, 474), (606, 465), (654, 444), (705, 430), (754, 425), (795, 423), 
 (825, 426), (821, 443), (794, 466), (774, 472), (733, 468), (679, 421), (622, 379), 
 (578, 330), (540, 305), (489, 277), (442, 284), (424, 310), (417, 323), (425, 346), 
 (460, 375), (512, 417), (563, 422), (610, 377), (677, 317), (733, 291), (787, 298), 
 (817, 328), (824, 368), (823, 401), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), (812, 419), 
 (812, 419)]

如果我用ReadableStream中的相同字符串替换流(在响应中),则响应会正确返回。我使用的是最新版本的Chrome。

我有什么遗失的吗?

以下是:

addEventListener('fetch', function(event) {
  const stream = new ReadableStream({
  start(controller) {
    controller.enqueue('test')
    controller.close()
  }});
  event.waitUntil(event.respondWith(new Response(stream, {headers: {'Content-Type': 'text/html; charset=utf-8'}})))
});

服务工作者肯定正确加载并响应获取。

1 个答案:

答案 0 :(得分:0)

解决!需要首先编码文本:)

controller.enqueue(new TextEncoder().encode('test'))