Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

373
Visualizações
How to retrieve an http request headers item from a symbol map?

I am trying to retrieve a particular request header from an apolloserver request (i.e. the request object from a GraphQLRequestContext), inside a a plugin.

logging the headers object logs out as:

Headers {
  [Symbol(map)]: [Object: null prototype] {
    'content-type': [ 'application/json' ],
    user: [
      '{...(redacted)...}'
    ],
    'x-header-foo': [ '234' ],
    accept: [ '*/*' ],
    'content-length': [ '256' ],
    'user-agent': [ 'node-fetch/1.0 (+https://github.com/bitinn/node-fetch)' ],
    'accept-encoding': [ 'gzip,deflate' ],
    connection: [ 'close' ],
    host: [ 'localhost:3000' ]
  }
}

but headers['x-header-foo'] yields undefined. How do I get the header value? I have not used symbols much so far.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As you said rightly, Headers are Symbols and not Objects, so to get value, you use the get method

Read more about Symbols here Symbol is a built-in object whose constructor returns a symbol primitive — also called a Symbol value or just a Symbol — that's guaranteed to be unique.

Headers are Symbols and not Objects, so to get value, you use the get method

const host = req.headers.get("host"); // stackoverflow.com

If you wish to destructure using Symbols:

let symbol = Symbol()
let obj = { [symbol] : 'value'}
let { [symbol]: alias } = obj

console.log(alias)
about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda