MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / proxyWebSocket

Function proxyWebSocket

scripts/proxy-utils.mjs:410–443  ·  view source on GitHub ↗
(req, socket, head, target)

Source from the content-addressed store, hash-verified

408 }
409
410 function proxyWebSocket(req, socket, head, target) {
411 if (xfwd) forwardClientOrigin(req);
412 metrics.activeWebSockets += 1;
413 metrics.totalWebSockets += 1;
414 const finish = once(() => {
415 metrics.activeWebSockets = Math.max(0, metrics.activeWebSockets - 1);
416 });
417 socket.on("close", finish);
418 socket.on("error", finish);
419
420 try {
421 proxy.ws(req, socket, { target }, head).catch((err) => {
422 metrics.totalErrors += 1;
423 if (!isBenignSocketError(err)) {
424 console.error(
425 `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`,
426 err,
427 );
428 }
429 socket.destroy();
430 finish();
431 });
432 } catch (err) {
433 metrics.totalErrors += 1;
434 if (!isBenignSocketError(err)) {
435 console.error(
436 `[${label}] WebSocket proxy error for ${req.url} -> ${target}:`,
437 err,
438 );
439 }
440 socket.destroy();
441 finish();
442 }
443 }
444
445 function dumpMetrics() {
446 console.log(

Callers

nothing calls this directly

Calls 5

forwardClientOriginFunction · 0.85
onceFunction · 0.85
isBenignSocketErrorFunction · 0.85
errorMethod · 0.80
finishFunction · 0.70

Tested by

no test coverage detected