Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
QuiteAFancyEmerald
GitHub Repository: QuiteAFancyEmerald/Holy-Unblocker
Path: blob/master/lib/rammerhead/src/util/fixWebsocket.js
6530 views
1
// fixes unpipe error and crashes resulting from http requests to websocket proxy endpoint
2
3
const stages = require('testcafe-hammerhead/lib/request-pipeline/stages');
4
const { Duplex } = require('stream');
5
6
stages.unshift(function fixWebsocket(ctx) {
7
ctx.isWebSocket = ctx.res instanceof Duplex;
8
});
9
10
// fixes EPIPE error when trying to write head to a closed socket
11
const hammerheadWS = require('testcafe-hammerhead/lib/request-pipeline/websocket');
12
const respondOnWebSocket = hammerheadWS.respondOnWebSocket;
13
hammerheadWS.respondOnWebSocket = function (ctx) {
14
ctx.res.on('error', (err) => {
15
if (err.code !== 'EPIPE') {
16
console.error('Unknown crash-inducing error:', err);
17
}
18
// cleanup end will automatically be handled by the 'end' listener
19
});
20
respondOnWebSocket(ctx);
21
};
22
23