Skip to content

Fetch failed when setting host: header correctly #2318

@infinity0

Description

@infinity0

Reproducible By

$ node
Welcome to Node.js v18.13.0.
Type ".help" for more information.
> const { fetch } = require('undici');
undefined
> await fetch("https://bing.com/translator", { headers: { host: 'bing.com' } });
Uncaught TypeError: fetch failed
    at fetch ($PWD/node_modules/undici/index.js:110:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async REPL2:1:33 {
  cause: Error: Client network socket disconnected before secure TLS connection was established
      at connResetException (node:internal/errors:718:14)
      at TLSSocket.onConnectEnd (node:_tls_wrap:1600:19)
      at TLSSocket.emit (node:events:525:35)
      at TLSSocket.emit (node:domain:552:15)
      at endReadableNT (node:internal/streams/readable:1359:12)
      at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
    code: 'ECONNRESET',
    path: undefined,
    host: 'www.bing.com',
    port: 443,
    localAddress: null
  }
}
> await fetch("https://bing.com/translator");
Response {
  [Symbol(realm)]: null,
[ .. all good without explicit host: .. ]

The bug happens with bing.com because it tries to redirect to www.bing.com; it doesn't happen for domains that don't redirect, such as fanyi.baidu.com.

Environment

software version
undici v5.25.4
node v18.13.0
Operating System Debian GNU/Linux trixie/sid

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions