Path: blob/master/lib/rammerhead/src/util/fixWebsocket.js
6530 views
// fixes unpipe error and crashes resulting from http requests to websocket proxy endpoint12const stages = require('testcafe-hammerhead/lib/request-pipeline/stages');3const { Duplex } = require('stream');45stages.unshift(function fixWebsocket(ctx) {6ctx.isWebSocket = ctx.res instanceof Duplex;7});89// fixes EPIPE error when trying to write head to a closed socket10const hammerheadWS = require('testcafe-hammerhead/lib/request-pipeline/websocket');11const respondOnWebSocket = hammerheadWS.respondOnWebSocket;12hammerheadWS.respondOnWebSocket = function (ctx) {13ctx.res.on('error', (err) => {14if (err.code !== 'EPIPE') {15console.error('Unknown crash-inducing error:', err);16}17// cleanup end will automatically be handled by the 'end' listener18});19respondOnWebSocket(ctx);20};212223