Skip to content

Instantly share code, notes, and snippets.

@weilu
Created June 11, 2014 01:57
Show Gist options
  • Save weilu/2424d5f7dbb82d54f94c to your computer and use it in GitHub Desktop.
Save weilu/2424d5f7dbb82d54f94c to your computer and use it in GitHub Desktop.
express.js: test cookie content
var cookieParser = require('express').cookieParser(process.env.COOKIE_SALT)
function parseCookie(cookie){
var fakeReq = {headers: {cookie: cookie}}
cookieParser(fakeReq, null, function(){
console.log(fakeReq)
})
}
parseCookie("connect.sid=s%3A70TTUUz60sHREcMcDsBuTWBf.2vKZjdW%2B2ecr%2Bk8kI%2Frno%2BoqdQmSPHFuz1g4V7OJzSM; Path=/; HttpOnly")
//rakeReq yields:
{ headers: { cookie: 'connect.sid=s%3A70TTUUz60sHREcMcDsBuTWBf.2vKZjdW%2B2ecr%2Bk8kI%2Frno%2BoqdQmSPHFuz1g4V7OJzSM; Path=/; HttpOnly' },
secret: 'secret',
cookies: { Path: '/' },
signedCookies: { 'connect.sid': '70TTUUz60sHREcMcDsBuTWBf' } }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment