nodejs / nodejs/node

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

Aperta
#64,405 4 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

http
Lingua principale
JavaScript
Stelle
122k
Fork
37.3k
Merge medio
4g 2h
PR unite (30g)
283

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia dal punto di ingresso delle richieste di node:http e traccia il modo in cui viene memorizzato l’array options.headers prima che vengano chiamati getHeaders(), getHeaderNames() e getRawHeaderNames(). Riproduci l’esempio, quindi verifica che questi metodi riportino gli header in modo coerente con le opzioni in forma di oggetto, preservando al contempo gli header della richiesta emessi.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
javascript, nodejs
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
3/5
Tempo stimato
1-2 giorni
Stato di attività
Tranquilla
Chiarezza
Abbastanza chiara
Idoneità per principianti
52/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.