chimurai / http-proxy-middleware

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

ERR_HTTP_HEADERS_SENT from onProxyReq with https-proxy-agent #957

Open leonardo3dp opened 6 months ago

leonardo3dp commented 6 months ago

Checks

Describe the bug (be clear and concise)

I can't change the headers using onProxyReq when I set the agent using https-proxy-agent

Step-by-step reproduction instructions

1. Configure proxy middleware with a https-proxy-agent agent
2. Add an onProxyReq handler that sets a header
3. Apply load with a larger number of threads/VUs than available sockets.

Expected behavior (be clear and concise)

No errors, perhaps timeouts due to socket availability.

How is http-proxy-middleware used in your project?

const express = require('express');
const { createProxyMiddleware } =  require('http-proxy-middleware');
const { HttpsProxyAgent } = require('https-proxy-agent');

const proxyAgent = new HttpsProxyAgent('http://111.111.111.:1111') ;

const apiHost = 'https://exemple.com';

const proxyMiddleware = createProxyMiddleware({
    agent: proxyAgent,
    target: apiHost,
    changeOrigin: true,
    onProxyReq: (proxyReq, req, res) => {
        proxyReq.setHeader('TEST', 'hello world');
    }
});

const server = express();
server.get('/', proxyMiddleware);

server.listen(3000);

What http-proxy-middleware configuration are you using?

{
    agent: proxyAgent,
    target: apiHost,
    changeOrigin: true,
    onProxyReq: (proxyReq, req, res) => {
        proxyReq.setHeader('TEST', 'hello world');
    }
}

What OS/version and node/version are you seeing the problem?

Node v16
OS: Windows 10

Additional context (optional)

No response

squapllabs commented 6 months ago

same issue even without using agent: proxyAgent,

Toolsclub commented 5 months ago

the answer: https://github.com/chimurai/http-proxy-middleware/issues/472#issuecomment-787473184