Skip to content

Issue with undici.request and Headers Global Object #2700

@JaoodxD

Description

@JaoodxD

Bug Description

Undici's request function appears to be skipping headers that are constructed using the Headers global object.

Reproducible By

  1. Create an instance of Headers class.
  2. Add header with set/append.
  3. Pass headers instance to request.
const headers = new Headers()
headers.append('random-header', 'hello world')

const res = await request('http://localhost:3001', { headers })

Full reproducable example can be found in following repo

Expected Behavior

I expect the undici.request function to treat instances of the Headers class the same way it handles plain JavaScript objects passed to options.
Specifically, I anticipate that the headers, when constructed using the Headers class, should be seamlessly attached to the HTTP request.

Logs & Screenshots

{
  host: 'localhost:3000',
  connection: 'keep-alive',
  'random-header': 'hello world' // passed as plain object
}
{ host: 'localhost:3001', connection: 'keep-alive' } // as Headers instance

Environment

OS: Windows 10
Nodejs: v20.8.0
undici: v6.6.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions