test: fix WebKit socks proxy tests (#19035)

Fixes https://github.com/microsoft/playwright/issues/18301
This commit is contained in:
Max Schmitt 2022-11-23 13:03:38 -10:00 committed by GitHub
parent 30debb5110
commit b84a7a9e57
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -49,9 +49,11 @@ export const serverFixtures: Fixtures<ServerFixtures, ServerWorkerOptions> = {
const socksServer = socks.createServer((info, accept, deny) => {
const socket = accept(true);
if (socket) {
// Catch and ignore ECONNRESET errors.
socket.on('error', () => {});
if (!socket)
return;
socket.on('data', data => {
if (!data.toString().includes('\r\n\r\n'))
return;
const body = '<html><title>Served by the SOCKS proxy</title></html>';
socket.end([
'HTTP/1.1 200 OK',
@ -61,7 +63,10 @@ export const serverFixtures: Fixtures<ServerFixtures, ServerWorkerOptions> = {
'',
body
].join('\r\n'));
}
});
// Catch and ignore ECONNRESET errors.
socket.on('error', () => {});
setTimeout(() => socket.end(), 1000);
});
const socksPort = port + 2;
socksServer.listen(socksPort, 'localhost');