Skip to content
Myr

Added Express.cookie() for get/setting

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by visionmedia · committed by visionmedia · parent 20cdbde · Browse files · 3 files+56 added−6 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+56 added−6 removed

  • tests:+19 added−0 removed
  • other:+37 added−6 removed

3 files+56 added−6 removed

modified:lib/express.core.js+35 added-6 removed
2 unmodified lines
3 Express = { 4 version : '0.0.1',5 routes : [],6 7 // --- Response8 9 response : {10 body : null,11 status : 200,10 headers : {}12 headers : {},13 cookie : {}14 },15 16 // --- Defaults17 18 defaults : {19 cookie : {20 expires : 30021 },13 defaultRoute : {14 callback : function() {15 Express.status('Not Found')16 'Not Found'22 route : {23 callback : function() {24 Express.status('Not Found')25 'Not Found'26 }27 }28 },29 30 /**
112 unmodified lines
143 param : function(key, defaultValue) {144 return this.request.uri.params[key] || defaultValue145 },146 147 148 /**149 * Return cookie _key_. When _value_ is present150 * then a response cookie field will be set.151 *152 * @param {string} key153 * @param {string} value154 * @return {string, hash}155 * @api public156 */157158 cookie : function(key, value) {159 if (!value) return this.request.cookie[key]160 return this.response.cookie[key] = {161 key : key,162 value : value163 }164 },165 166 /**167 * Parse _params_, splitting { user[info][name] : 'tj' } into168 * { user : { info : { name : 'tj' }}}169 *170 * @param {hash} params
192 unmodified lines
363 * @api private364 */365 366 callRouteFor : function(request) {338 var route = this.findRouteFor(request) || this.defaultRoute367 var route = this.findRouteFor(request) || this.defaults.route368 if (route.keys)369 for (i = 0, len = route.keys.length; i < len; ++i) 370 this.request.uri.params[route.keys[i]] = Express.captures[i+1] || null371 return this.eval(Express.contentsOf(route.callback)).toString()
109 unmodified lines
modified:spec/spec.core.js+19 added
modified:README.rdoc+2 added
10 unmodified lines
11* Sexy DSL12* Mime helpers13* Nested parameter parsing (user[name]=tj == { user : { name : 'tj' }})14* Full test coverage15* Cookie support16* Non polluting (so you can use it with your fav JavaScript libraries :) )17* Routing18 * string matching19 * regexp with captures20 * param key substitution
60 unmodified lines