Persistant cookies
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by visionmedia · committed by visionmedia · parent 9f4d2be · Browse files · 2 files·+22 added−13 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+22 added−13 removed
- tests:+4 added−6 removed
- other:+18 added−7 removed
Provenance
- Commit
73d1d67- Tree
0977eaa- Author
visionmedia <tj@vision-media.ca>- Committer
visionmedia <tj@vision-media.ca>- Parent
9f4d2be
2 files changed+22 added−13 removed
modified:lib/express.core.js+18 added-7 removed
15 unmodified lines16 // --- Defaults17 18 defaults : {19 cookie : {20- expires : 30020+ maxAge : 360021 },22 route : {23 callback : function() {24 Express.status('Not Found')10 unmodified lines35 */36 37 start : function(port) {38 this.server.listen(port || 3000, function(request, response){39+ // TODO: hooks / modules40 request.headers = Express.arrayToHash(request.headers)41 request.cookie = Express.parseCookie(request.headers['Cookie'])42 request.uri.params = Express.parseNestedParams(request.uri.params)43 request.uri.path = Express.normalizePath(request.uri.path)44 Express.request = request45+ Express.response.cookie = request.cookie46 Express.response.body = Express.callRouteFor(request)45- response.sendHeader(Express.response.status, Express.hashToArray(Express.response.headers))47+ response.sendHeader(Express.response.status, Express.prepareResponseHeaders(Express.hashToArray(Express.response.headers)))48 response.sendBody(Express.response.body || '')49 response.finish()50 })51 },13 unmodified lines65 puts('Express listening to http://localhost:' + port)66 }67 },68 69+ prepareResponseHeaders : function(headers) {70+ return headers71+ },72+ 73 /**74 * Return an associative array generated75 * from the key / value pairs in _hash_.76 *84 unmodified lines161 * @api public162 */163 164 cookie : function(key, value) {159- if (!value) return this.request.cookie[key]160- return this.response.cookie[key] = {161- key : key,162- value : value163- }165+ return value ? this.response.cookie[key] = value :166+ this.response.cookie[key]167 },168 169 /**170 * Parse _params_, splitting { user[info][name] : 'tj' } into292 unmodified lines463 p(request.cookie)464 param('operation') + 'ing ' + param('name')465 })466 467+get('cookies', function(){468+ cookie('foo', 'bar')469+ p(request.headers)470+ p(response.headers)471+ p(response.cookie)472+ 'Wahoo!'473+})474+475 get('articles', function(){476 display('spec/data/example.html.js')477 'list of articles'478 })13 unmodified linesmodified:spec/spec.core.js+4 added-6 removed
69 unmodified lines707172737475767475767778798180818283848687858687888973 unmodified lines69 unmodified lines end describe '.cookie()' before_each cookie = 'expires=Fri, 31-Dec-2010 23:59:59 GMT; path=/; q=foo%3dbar; domain=example.net' Express.request = {} Express.request.cookie = Express.parseCookie(cookie) cookie = 'path=/; q=foo%3dbar; domain=.example.net' Express.response.cookie = Express.parseCookie(cookie) end it 'should return cookie value when key passed' Express.cookie('path').should.eql '/' Express.cookie('domain').should.eql 'example.net' Express.cookie('domain').should.eql '.example.net' end it 'should set response cookies when value passed' Express.cookie('foo', 'bar') Express.response.cookie.foo.key.should.eql 'foo' Express.response.cookie.foo.value.should.eql 'bar' Express.cookie('foo').should.eql 'bar' end end describe '.argsArray()'73 unmodified lines