summaryrefslogtreecommitdiff
path: root/ext/http
diff options
context:
space:
mode:
authorLeo Kettmeir <crowlkats@toaxl.com>2022-01-06 17:41:16 +0100
committerGitHub <noreply@github.com>2022-01-06 17:41:16 +0100
commit2067820714fea49be1692fa678754488ace8228b (patch)
tree2decf412d953016a5b4853e77b04f94466a588dc /ext/http
parent46f2ff120587cd1cb7b11e66d41ad6ad46fb09a8 (diff)
feat(ext/websocket): server automatically handle ping/pong for incoming WebSocket (#13172)
Diffstat (limited to 'ext/http')
-rw-r--r--ext/http/01_http.js22
1 files changed, 20 insertions, 2 deletions
diff --git a/ext/http/01_http.js b/ext/http/01_http.js
index 7620d154a..4922ed07a 100644
--- a/ext/http/01_http.js
+++ b/ext/http/01_http.js
@@ -17,8 +17,17 @@
const { BadResource, Interrupted } = core;
const { ReadableStream } = window.__bootstrap.streams;
const abortSignal = window.__bootstrap.abortSignal;
- const { WebSocket, _rid, _readyState, _eventLoop, _protocol, _server } =
- window.__bootstrap.webSocket;
+ const {
+ WebSocket,
+ _rid,
+ _readyState,
+ _eventLoop,
+ _protocol,
+ _server,
+ _idleTimeoutDuration,
+ _idleTimeoutTimeout,
+ _serverHandleIdleTimeout,
+ } = window.__bootstrap.webSocket;
const {
ArrayPrototypeIncludes,
ArrayPrototypePush,
@@ -277,6 +286,13 @@
ws.dispatchEvent(event);
ws[_eventLoop]();
+ if (ws[_idleTimeoutDuration]) {
+ ws.addEventListener(
+ "close",
+ () => clearTimeout(ws[_idleTimeoutTimeout]),
+ );
+ }
+ ws[_serverHandleIdleTimeout]();
}
}
} finally {
@@ -378,6 +394,8 @@
setEventTargetData(socket);
socket[_server] = true;
response[_ws] = socket;
+ socket[_idleTimeoutDuration] = options.idleTimeout ?? 120;
+ socket[_idleTimeoutTimeout] = null;
return { response, socket };
}