Skip to content

Instantly share code, notes, and snippets.

@davidkrisch
Created February 13, 2012 18:24
Show Gist options
  • Save davidkrisch/1818829 to your computer and use it in GitHub Desktop.
Save davidkrisch/1818829 to your computer and use it in GitHub Desktop.
Express Cookie Handling - why does Connect call toLowerCase on all cookie names?
var express = require('express');
var app = express.createServer();
app.use(express.cookieParser());
app.get('/', function(req, res) {
// Prints undefined
process.stdout.write('req.cookies.RelayState = '
+ JSON.stringify(req.cookies.RelayState) + '\n');
// Prints undefined
process.stdout.write('req.cookies[\'RelayState\'] = '
+ JSON.stringify(req.cookies['RelayState']) + '\n');
// Prints clever cookie
process.stdout.write('req.cookies[\'relaystate\'] = '
+ JSON.stringify(req.cookies['relaystate']) + '\n');
// Prints clevercookie
process.stdout.write('req.cookies.relaystate = '
+ JSON.stringify(req.cookies.relaystate) + '\n');
res.cookie('RelayState', 'clevercookie');
res.send('hello world');
process.stdout.write('----------------\n');
process.stdout.write(JSON.stringify(req.cookies) + '\n');
process.stdout.write('----------------\n');
});
app.listen(3000);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment