http-proxy icon indicating copy to clipboard operation
http-proxy copied to clipboard

how to use createWsClientTransformStream

Open lucaschan1020 opened this issue 1 year ago • 1 comments

if i understand correctly, createWsClientTransformStream is for transforming message from client to server, do u have any example on how to use this method? thanks in advance

lucaschan1020 avatar Oct 06 '24 15:10 lucaschan1020

i have tried this, https://github.com/http-party/node-http-proxy/pull/1301#issuecomment-468059087 does not work

lucaschan1020 avatar Oct 06 '24 15:10 lucaschan1020

hi @lucaschan1020, the createWsClientTransformStream method is used to transform WS messages between the client and server (in theory).

const proxy = httpProxy.createProxyServer({
  ws: true,
  target: 'ws://example.com',
  createWsClientTransformStream: (req, proxyReq, proxyRes) => {
    const { PassThrough } = require('stream');
    const transformStream = new PassThrough();

    transformStream.on('data', (chunk) => {
      const modifiedChunk = chunk.toString().toUpperCase();
      proxyReq.write(modifiedChunk);
    });

    return transformStream;
  }
});

I believe it works, can you test it and get back to me (your test code + error)?

JoaoOtavioS avatar Oct 17 '24 20:10 JoaoOtavioS