nodejs / nodejs/node

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

未关闭
#64,405 4 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

http
主要语言
JavaScript
星标
122k
派生
37.4k
平均合并
4 天 3 小时
30 天内合并 PR
272

描述

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

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

从 node:http 请求入口开始,跟踪在调用 getHeaders()、getHeaderNames() 和 getRawHeaderNames() 之前 options.headers 数组是如何存储的。重现该示例,然后验证这些方法报告的标头是否与对象形式的 options 一致,同时保留发出的请求标头。

由索引模型根据 Issue 内容生成。

评估

技术栈
javascript, nodejs
领域
api, backend
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
冷清
描述清晰度
基本清楚
新手友好度
52/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。