nodejs / nodejs/node

`req.getHeaders()` does not return values set using "rawHeaders" array

Open
#64,405 4 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

http
Dominant language
JavaScript
Stars
122k
Forks
37.3k
Avg merge
4d 2h
Merged PRs (30d)
283

Description

Version

v24.18.0

Platform
Darwin MBPM.local 25.5.0 Darwin Kernel Version 25.5.0: Tue Jun  9 22:28:29 PDT 2026; root:xnu-12377.121.10~1/RELEASE_ARM64_T6030 arm64
Subsystem

http

What steps will reproduce the bug?

Headers set using the message.rawHeaders format are not available on the request's getHeaders() method

import { get } from 'node:http'

const request = get(
  'http://localhost:3000',
  {
    headers: ['foo', 'bar', 'baz', 'qux']
  },
  (res) => {
    let data = ''

    res.on('data', (chunk) => {
      data += chunk
    })

    res.on('end', () => {
      console.log(data)
    })
  }
)

request.on('error', () => {})

console.log(request.getHeaders()) // [Object: null prototype] {}
console.log(request.getHeaderNames()) // []
console.log(request.getRawHeaderNames()) // []
console.log(request._header) // GET / HTTP/1.1\r\nfoo: bar\r\nbaz: qux\r\nConnection: keep-alive

How often does it reproduce? Is there a required condition?

Always

What is the expected behavior? Why is that the expected behavior?

One would expect req.getHeaders() (and friends) to return a consistent value, whether an object or an array was passed as argument.

What do you see instead?

req.getHeaders() appears to be empty when request options are built using an array notation.

Additional information

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start at the node:http request entry point and trace how the options.headers array is stored before getHeaders(), getHeaderNames(), and getRawHeaderNames() are called. Reproduce the example, then verify that these methods report the headers consistently with object-form options while preserving the emitted request headers.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs
Domain
api, backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.