chimurai / http-proxy-middleware

:zap: The one-liner node.js http-proxy middleware for connect, express, next.js and more
MIT License
10.68k stars 826 forks source link

Update response-interceptor.ts #851

Closed gauravpant1306 closed 4 months ago

gauravpant1306 commented 1 year ago

response interceptor to handle streams if stream is encrypted by custom algorithm

Description

Changed response-interceptor interceptor definition and implementation

Motivation and Context

If stream is encrypted and chunks are of different size, we need to handle those streams, decode and combine

How has this been tested?

Yes, we can use it like this

 onProxyRes: responseInterceptor(
      async (bufferArray) => {
         let encryptedBuffer=[]
         buffer = Buffer.from('','base64')
         let tempBuffer = Buffer.from('', 'base64');
         bufferArray.forEach(chunk => {
            if(chunk.toString().includes(","))
            {
                let split= chunk.toString().split(",");
                tempBuffer = Buffer.concat([ tempBuffer,Buffer.from(split[0])])
                encryptedBuffer.push(tempBuffer)
                tempBuffer = Buffer.from('', 'base64');  
                if(split.length>1)
                {
                    for (let index = 1; index < split.length; index++) {
                        if(split[index]='')
                        {
                            continue;
                        }
                        tempBuffer = Buffer.concat([tempBuffer,Buffer.from(split[index])])
                    }
                }
            }
            else{
                tempBuffer = Buffer.concat([ tempBuffer,chunk])
            }

});

for (let index = 0; index < encryptedBuffer.length; index++) {

   let response = encryptedBuffer[index].toString();

   const decryptResponse = await decrypt.decryptPayload(
      response,
   );

 buffer = Buffer.concat([buffer,Buffer.from(decryptResponse, 'base64')])

}
return buffer;

      }
   ),

Types of changes

Checklist:

edit: code formatting

lgtm-com[bot] commented 1 year ago

This pull request introduces 2 alerts when merging 291d388b397254ad7a27f7577f92060566285a78 into a9fe840aaad6f523faa5d06c0e7b6244e82712e0 - view on LGTM.com

new alerts:

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine :gear: that powers LGTM.com. For more information, please check out our post on the GitHub blog.

lgtm-com[bot] commented 1 year ago

This pull request introduces 2 alerts when merging ffc4b0b963ef3e6c9119865ed81175e2c9984aea into a9fe840aaad6f523faa5d06c0e7b6244e82712e0 - view on LGTM.com

new alerts:

Heads-up: LGTM.com's PR analysis will be disabled on the 5th of December, and LGTM.com will be shut down ⏻ completely on the 16th of December 2022. Please enable GitHub code scanning, which uses the same CodeQL engine :gear: that powers LGTM.com. For more information, please check out our post on the GitHub blog.

chimurai commented 4 months ago

Looks like you modified compiled typescript code.

Please open a issue to describe the motivation for this feature/change