Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

98
Vistas
encode object into cookie string for testing

I'm using cookies to pass the session about the logged in user, and on the server I can set and get them fine:

res.cookie("foo", { bar: "baz" })

// later on
console.log(req.cookies.foo) // { bar: "baz" }

Now, I want to test it, and I need to set the cookie header, but I don't know how to convert an object, i.e. { bar: "baz" }, to the header string the cookie evaluates to enter image description here

What's the algorithm used here?

(I'm using supertest but it shouldn't matter IMO)

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

In express by default the cookie is encoded, you need to pass the options to keep it as a string.

encode Function - A synchronous function used for cookie value encoding. Defaults to encodeURIComponent.

// Custom encoding
res.cookie("foo", { bar: "baz" }, {encode: String})

You can check here for more details.

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda