httpxy
httpxy copied to clipboard
Add port to the `host` breaks some website
Environment
nodejs: v20.12.0 httpxy: v0.1.5(latest)
Reproduction
You have to download this project to run locally (Some TLS error prevents it from running in Stackblitz).
Describe the bug
- The
/api/httpxy
is usinghttpxy
(this repo)
import { createProxyServer } from 'httpxy';
const proxy = createProxyServer({
target: 'https://baidu.com',
changeOrigin: true,
});
export default defineEventHandler(async (event) => {
await proxy.web(event.node.req, event.node.res);
});
- The
/api/http-proxy
is using node-http-proxy
import HttpProxy from 'http-proxy'
const httpProxy = new HttpProxy({
target: 'https://baidu.com',
changeOrigin: true,
})
export default defineEventHandler(async event => {
await new Promise<void>((resolve, reject) => {
httpProxy.web(event.node.req, event.node.res, undefined, err => {
err ? reject(err) : resolve()
})
})
})
- Open the network panel, click
httpxy
andhttp-proxy
buttons to both fetch https://baidu.com (the Chinese largest search engine, I just use it as an example). -
httpxy
response with a405
(❌), and thehttp-proxy
response with a302
(✅).
I have verified it's the Host
that caused the wrong response(maybe some check by baidu.com),
- When using
httpxy
, the requestHost
isbaidu.com:443
Caused by this:
https://github.com/unjs/httpxy/blob/07778fb8984c7f63d5cd00e38b787e7da27209fc/src/_utils.ts#L108-L110
- When using
http-proxy
, the requestHost
isbaidu.com
I'm not saying Baidu's strategy in the response, I just wonder why we add the port
to the Host
, it might break some other sites as well.
Sorry to disturb if anything I misunderstood ❤️.
Additional context
No response
Logs
No response