laggingreflex
laggingreflex

Reputation: 34667

Retrieve and unjumble cookie data from superagent response header

I'm using supertest and trying to get the cookie data cleanly

agent.post('/login').send('username:u','password:p').end(function(err, res) {
    agent.cookie = res.req._headers.cookie;
});

But to cookie data I get is jumbled up

connect.sid=s%3Afc20GaiFXGNju1rxqDSOEiA4.W3XfTacI0xhk4gQ9Bdh1LLC%2FlhjnAwVmQkUX%2F7%2FJEAo

instead of cleanly like this (and the above is even longer for some reason)

{ 'connect.sid': 'T0jrnU09DzCYN68FsgspuY5g' }

How do I get the latter?

Upvotes: 3

Views: 1148

Answers (1)

laggingreflex
laggingreflex

Reputation: 34667

require('cookie').parse(decodeURIComponent(cookie))

Upvotes: 2

Related Questions