MCPcopy Index your code
hub / github.com/browserless/browserless / handleWebSocket

Method handleWebSocket

src/server.ts:392–413  ·  view source on GitHub ↗
(
    request: http.IncomingMessage,
    socket: stream.Duplex,
    head: Buffer,
  )

Source from the content-addressed store, hash-verified

390 }
391
392 protected async handleWebSocket(
393 request: http.IncomingMessage,
394 socket: stream.Duplex,
395 head: Buffer,
396 ) {
397 const req = request as Request;
398
399 // A client resetting the connection mid-handshake emits 'error' on the
400 // raw socket; with no listener that's an uncaught exception that kills
401 // the process.
402 socket.on('error', (err) => {
403 this.logger.error(`WebSocket socket error: ${err.message}`);
404 });
405
406 // Same rationale as handleRequest: a throw here is an unhandled
407 // rejection on the 'upgrade' listener and crashes the process.
408 try {
409 await this.handleWebSocketUnsafe(req, socket, head);
410 } catch (e: unknown) {
411 this.handleErrorRequest(e as Error, socket, req);
412 }
413 }
414
415 protected async handleWebSocketUnsafe(
416 req: Request,

Callers 1

handleUpgradeMethod · 0.95

Calls 3

handleWebSocketUnsafeMethod · 0.95
handleErrorRequestMethod · 0.95
errorMethod · 0.80

Tested by

no test coverage detected