From 526e4118fa09fdaba896890bd1da9da30a012180 Mon Sep 17 00:00:00 2001 From: Max Schmitt Date: Tue, 23 Jul 2024 15:44:16 +0200 Subject: [PATCH] chore: use socks.Duplex constructor instead of extending (#31816) --- .../socksClientCertificatesInterceptor.ts | 19 +++++++------------ 1 file changed, 7 insertions(+), 12 deletions(-) diff --git a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts index daadd8b5cc..6cd418a8c9 100644 --- a/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts +++ b/packages/playwright-core/src/server/socksClientCertificatesInterceptor.ts @@ -26,17 +26,6 @@ import type { SocksSocketClosedPayload, SocksSocketDataPayload, SocksSocketReque import { SocksProxy } from '../common/socksProxy'; import type * as channels from '@protocol/channels'; -class SocksConnectionDuplex extends stream.Duplex { - constructor(private readonly writeCallback: (data: Buffer) => void) { - super(); - } - override _read(): void { } - override _write(chunk: Buffer, encoding: BufferEncoding, callback: (error?: Error | null | undefined) => void): void { - this.writeCallback(chunk); - callback(); - } -} - class SocksProxyConnection { private readonly socksProxy: ClientCertificatesProxy; private readonly uid: string; @@ -89,7 +78,13 @@ class SocksProxyConnection { } private _attachTLSListeners() { - this.internal = new SocksConnectionDuplex(data => this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data })); + this.internal = new stream.Duplex({ + read: () => {}, + write: (data, encoding, callback) => { + this.socksProxy._socksProxy.sendSocketData({ uid: this.uid, data }); + callback(); + } + }); const internalTLS = new tls.TLSSocket(this.internal, { isServer: true, key: fs.readFileSync(path.join(__dirname, '../../bin/socks-certs/key.pem')),