function $7c564b05baed9a55$var$responseInterceptor(interceptor) {
    return async function proxyRes(proxyRes, req, res) {
        const originalProxyRes = proxyRes;
        let buffer = Buffer.from('', 'utf8');
        // decompress proxy response
        const _proxyRes = $7c564b05baed9a55$var$decompress(proxyRes, proxyRes.headers['content-encoding']);
        // concat data stream
        _proxyRes.on('data', (chunk)=>buffer = Buffer.concat([
                buffer,
                chunk
            ])
        );
        _proxyRes.on('end', async ()=>{
            // copy original headers
            $7c564b05baed9a55$var$copyHeaders(proxyRes, res);
            // call interceptor with intercepted response (buffer)
            const interceptedBuffer = Buffer.from(await interceptor(buffer, originalProxyRes, req, res));
            // set correct content-length (with double byte character support)
            res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf8'));
            res.write(interceptedBuffer);
            res.end();
        });
        _proxyRes.on('error', (error)=>{
            res.end(`Error fetching proxied request: ${error.message}`);
        });
    };
}
/**
 * Intercept responses from upstream.
 * Automatically decompress (deflate, gzip, brotli).
 * Give developer the opportunity to modify intercepted Buffer and http.ServerResponse
 *
 * NOTE: must set options.selfHandleResponse=true (prevent automatic call of res.end())
 */
Intercept responses from upstream.
Automatically decompress (deflate, gzip, brotli).
Give developer the opportunity to modify intercepted Buffer and http.ServerResponse


Intercept responses from upstream . Automatically decompress ( deflate gzip brotli ) . Give developer the opportunity to modify intercepted Buffer and http . ServerResponse
function $7c564b05baed9a55$var$responseInterceptor(interceptor) {
    return async function proxyRes(proxyRes, req, res) {
        const originalProxyRes = proxyRes;
        let buffer = Buffer.from('', 'utf8');
        const _proxyRes = $7c564b05baed9a55$var$decompress(proxyRes, proxyRes.headers['content-encoding']);
        _proxyRes.on('data', (chunk)=>buffer = Buffer.concat([
                buffer,
                chunk
            ])
        );
        _proxyRes.on('end', async ()=>{
            $7c564b05baed9a55$var$copyHeaders(proxyRes, res);
            const interceptedBuffer = Buffer.from(await interceptor(buffer, originalProxyRes, req, res));
            res.setHeader('content-length', Buffer.byteLength(interceptedBuffer, 'utf8'));
            res.write(interceptedBuffer);
            res.end();
        });
        _proxyRes.on('error', (error)=>{
            res.end(`Error fetching proxied request: ${error.message}`);
        });
    };
}
function $7c564b05baed9a55$var$responseInterceptor ( interceptor ) { return async function proxyRes ( proxyRes , req , res ) { const originalProxyRes = proxyRes ; let buffer = Buffer . from ( '' , 'utf8' ) ; const _proxyRes = $7c564b05baed9a55$var$decompress ( proxyRes , proxyRes . headers [ 'content-encoding' ] ) ; _proxyRes . on ( 'data' , ( chunk ) => buffer = Buffer . concat ( [ buffer , chunk ] ) ) ; _proxyRes . on ( 'end' , async ( ) => { $7c564b05baed9a55$var$copyHeaders ( proxyRes , res ) ; const interceptedBuffer = Buffer . from ( await interceptor ( buffer , originalProxyRes , req , res ) ) ; res . setHeader ( 'content-length' , Buffer . byteLength ( interceptedBuffer , 'utf8' ) ) ; res . write ( interceptedBuffer ) ; res . end ( ) ; } ) ; _proxyRes . on ( 'error' , ( error ) => { res . end ( ` ${ error . message } ` ) ; } ) ; } ; }
Intercept responses from upstream.
Intercept responses from upstream .
// decompress proxy response // concat data stream // copy original headers // call interceptor with intercepted response (buffer) // set correct content-length (with double byte character support)