Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

proxyReq 事件改变 header User-Agent 无效 #1040

Open
2 tasks done
h0medev2024 opened this issue Sep 19, 2024 · 0 comments
Open
2 tasks done

proxyReq 事件改变 header User-Agent 无效 #1040

h0medev2024 opened this issue Sep 19, 2024 · 0 comments

Comments

@h0medev2024
Copy link

h0medev2024 commented Sep 19, 2024

Checks

Describe the bug (be clear and concise)

const proxyMiddleware = createProxyMiddleware({
target: 'https://xxx.aaa.com',
ws:true,
secure: false,
changeOrigin: true,
selfHandleResponse : true,
on: {
proxyReq: (proxyReq, req, res) => {

 // 抓包显示User-Agent未被改变
  proxyReq.setHeader('User-Agent', 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'); 

  // 抓包显示User-Agent未被改变
  req.headers['User-Agent'] = 'Mozilla/5.0 (iPhone; CPU iPhone OS 14_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148'; 

  console.log('[DEMO] Request header:' + req.rawHeaders);

  if (req.method == 'POST') {
    console.log('[DEMO] Request body:' + req.body);
  }
},
proxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
  const response = responseBuffer.toString('utf8');
  console.log('[DEMO] Response body:' + response);
  return responseBuffer;
}),
error: (err, req, res) => {
  console.log('[DEMO] Error:' + err.message);
},

},
logger: console,
});

如代码所示,代理出口抓包显示User-Agent未被改变
Mac 通过npn安装的最新版

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant