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

Add port to the host breaks some website #58

Open
kricsleo opened this issue Jul 10, 2024 · 0 comments
Open

Add port to the host breaks some website #58

kricsleo opened this issue Jul 10, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@kricsleo
Copy link

kricsleo commented Jul 10, 2024

Environment

nodejs: v20.12.0
httpxy: v0.1.5(latest)

Reproduction

stackblitz - reporduciton

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 using httpxy(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);
});
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()
    })
  })
})
  1. Open the network panel, click httpxy and http-proxy buttons to both fetch https://baidu.com (the Chinese largest search engine, I just use it as an example).
  2. httpxy response with a 405(❌), and the http-proxy response with a 302(✅).

I have verified it's the Host that caused the wrong response(maybe some check by baidu.com),

  • When using httpxy, the request Host is baidu.com:443

Caused by this:

httpxy/src/_utils.ts

Lines 108 to 110 in 07778fb

hasPort(outgoing.host)
? outgoing.host
: outgoing.host + ":" + outgoing.port;

  • When using http-proxy, the request Host is baidu.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

@kricsleo kricsleo added the bug Something isn't working label Jul 10, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant