Skip to content

request Does Not Support Multiple Headers #1806

Closed
@jd-carroll

Description

Bug Description

Even though the type definitions clearly state multiple headers (of the same name) are supported, it would appear they are not. Any time I try to set an [string] array value to a header an exception is thrown.

Note: Here are the types for IncomingHttpHeaders , non-single valued headers (ie. the ones explicitly listed) can appear multiple times in a request.
https://github.com/DefinitelyTyped/DefinitelyTyped/blob/878f77e0bbce48cc9c528484e525d7ad1432297c/types/node/http.d.ts#L47-L49

Reproducible By

const { request } = require('undici');
request('https://example.com', {
  method: 'GET',
  headers: {
    'X-Test-Header': ['a']
  }
}).then(() => console.log('success'))
.catch((err) => console.error(err));

Expected Behavior

The request to be sent with the X-Test-Header.

Environment

macOS 13.0.1
node: v18.12.1
undici: 5.14.0

Additional context

The issue is this line

undici/lib/core/request.js

Lines 274 to 276 in f6323f6

function processHeader (request, key, val) {
if (val && typeof val === 'object') {
throw new InvalidArgumentError(`invalid ${key} header`)

Note: An array is an object! (typeof [] === 'object' // true)

I could probably work-up a fix for this, but at this point I am way too frustrated to deal with this any more (sorry).

Important Note: It is also more likely than not, that I am doing something wrong. So please tell me where I've gone awry 😎

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