add Context#cookies support. Closes #7

need to add signing support in there as well
This commit is contained in:
TJ Holowaychuk 2013-08-20 21:51:14 -07:00
parent 1af71053a2
commit ca7be7b89f
3 changed files with 20 additions and 1 deletions

16
examples/cookies.js Normal file
View file

@ -0,0 +1,16 @@
var http = require('http');
var koa = require('..');
var app = koa();
app.use(function(){
return function *(){
if ('/favicon.ico' == this.path) return;
var n = ~~this.cookies.get('view') || 1;
this.cookies.set('view', n + 1);
this.body = n + ' views';
}
});
app.listen(3000);
console.log('listening on port 3000');

View file

@ -7,6 +7,7 @@ var debug = require('debug')('koa:app');
var Emitter = require('events').EventEmitter; var Emitter = require('events').EventEmitter;
var compose = require('koa-compose'); var compose = require('koa-compose');
var context = require('./context'); var context = require('./context');
var Cookies = require('cookies');
var Stream = require('stream'); var Stream = require('stream');
var http = require('http'); var http = require('http');
var co = require('co'); var co = require('co');
@ -217,5 +218,6 @@ function createContext() {
this.app = app; this.app = app;
this.req = req; this.req = req;
this.res = res; this.res = res;
this.cookies = new Cookies(req, res);
} }
} }

View file

@ -28,7 +28,8 @@
"qs": "0.6.5", "qs": "0.6.5",
"fresh": "0.2.0", "fresh": "0.2.0",
"negotiator": "0.2.7", "negotiator": "0.2.7",
"koa-compose": "1.0.0" "koa-compose": "1.0.0",
"cookies": "~0.3.6"
}, },
"devDependencies": { "devDependencies": {
"bytes": "*", "bytes": "*",