From 171d8b6635d9ba27b0aab64355805bdf41344a45 Mon Sep 17 00:00:00 2001 From: Douglas Christopher Wilson Date: Fri, 29 Jan 2016 13:26:00 -0500 Subject: [PATCH 01/11] 1.13.1 --- HISTORY.md | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index 727834eb..ffb63d71 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,5 +1,5 @@ -unreleased -========== +1.13.1 / 2016-01-29 +=================== * deps: parseurl@~1.3.1 - perf: enable strict mode diff --git a/package.json b/package.json index 8b945f2e..b9e15281 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "express-session", - "version": "1.13.0", + "version": "1.13.1", "description": "Simple session middleware for Express", "author": "TJ Holowaychuk (http://tjholowaychuk.com)", "contributors": [ From 59b1f56097cac572ba587db89aa12e0794611923 Mon Sep 17 00:00:00 2001 From: Cian Clarke Date: Wed, 2 Mar 2016 08:54:13 -0500 Subject: [PATCH 02/11] docs: fix session store list for CommonMark spec fixes #248 closes #280 --- README.md | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/README.md b/README.md index f81381f2..f2a6df6b 100644 --- a/README.md +++ b/README.md @@ -412,90 +412,111 @@ The following modules implement a session store that is compatible with this module. Please make a PR to add additional modules :) [![★][cassandra-store-image] cassandra-store][cassandra-store-url] An Apache Cassandra-based session store. + [cassandra-store-url]: https://www.npmjs.com/package/cassandra-store [cassandra-store-image]: https://img.shields.io/github/stars/webcc/cassandra-store.svg?label=%E2%98%85 [![★][cluster-store-image] cluster-store][cluster-store-url] A wrapper for using in-process / embedded stores - such as SQLite (via knex), leveldb, files, or memory - with node cluster (desirable for Raspberry Pi 2 and other multi-core embedded devices). + [cluster-store-url]: https://www.npmjs.com/package/cluster-store [cluster-store-image]: https://img.shields.io/github/stars/coolaj86/cluster-store.svg?label=%E2%98%85 [![★][connect-couchbase-image] connect-couchbase][connect-couchbase-url] A [couchbase](http://www.couchbase.com/)-based session store. + [connect-couchbase-url]: https://www.npmjs.com/package/connect-couchbase [connect-couchbase-image]: https://img.shields.io/github/stars/christophermina/connect-couchbase.svg?label=%E2%98%85 [![★][connect-dynamodb-image] connect-dynamodb][connect-dynamodb-url] A DynamoDB-based session store. + [connect-dynamodb-url]: https://github.com/ca98am79/connect-dynamodb [connect-dynamodb-image]: https://img.shields.io/github/stars/ca98am79/connect-dynamodb.svg?label=%E2%98%85 [![★][connect-mssql-image] connect-mssql][connect-mssql-url] A SQL Server-based session store. + [connect-mssql-url]: https://www.npmjs.com/package/connect-mssql [connect-mssql-image]: https://img.shields.io/github/stars/patriksimek/connect-mssql.svg?label=%E2%98%85 [![★][connect-monetdb-image] connect-monetdb][connect-monetdb-url] A MonetDB-based session store. + [connect-monetdb-url]: https://www.npmjs.com/package/connect-monetdb [connect-monetdb-image]: https://img.shields.io/github/stars/MonetDB/npm-connect-monetdb.svg?label=%E2%98%85 [![★][connect-mongo-image] connect-mongo][connect-mongo-url] A MongoDB-based session store. + [connect-mongo-url]: https://www.npmjs.com/package/connect-mongo [connect-mongo-image]: https://img.shields.io/github/stars/kcbanner/connect-mongo.svg?label=%E2%98%85 [![★][connect-mongodb-session-image] connect-mongodb-session][connect-mongodb-session-url] Lightweight MongoDB-based session store built and maintained by MongoDB. + [connect-mongodb-session-url]: https://www.npmjs.com/package/connect-mongodb-session [connect-mongodb-session-image]: https://img.shields.io/github/stars/mongodb-js/connect-mongodb-session.svg?label=%E2%98%85 [![★][connect-pg-simple-image] connect-pg-simple][connect-pg-simple-url] A PostgreSQL-based session store. + [connect-pg-simple-url]: https://www.npmjs.com/package/connect-pg-simple [connect-pg-simple-image]: https://img.shields.io/github/stars/voxpelli/node-connect-pg-simple.svg?label=%E2%98%85 [![★][connect-redis-image] connect-redis][connect-redis-url] A Redis-based session store. + [connect-redis-url]: https://www.npmjs.com/package/connect-redis [connect-redis-image]: https://img.shields.io/github/stars/tj/connect-redis.svg?label=%E2%98%85 [![★][connect-memcached-image] connect-memcached][connect-memcached-url] A memcached-based session store. + [connect-memcached-url]: https://www.npmjs.com/package/connect-memcached [connect-memcached-image]: https://img.shields.io/github/stars/balor/connect-memcached.svg?label=%E2%98%85 [![★][connect-session-knex-image] connect-session-knex][connect-session-knex-url] A session store using [Knex.js](http://knexjs.org/), which is a SQL query builder for PostgreSQL, MySQL, MariaDB, SQLite3, and Oracle. + [connect-session-knex-url]: https://www.npmjs.com/package/connect-session-knex [connect-session-knex-image]: https://img.shields.io/github/stars/llambda/connect-session-knex.svg?label=%E2%98%85 [![★][connect-session-sequelize-image] connect-session-sequelize][connect-session-sequelize-url] A session store using [Sequelize.js](http://sequelizejs.com/), which is a Node.js / io.js ORM for PostgreSQL, MySQL, SQLite and MSSQL. + [connect-session-sequelize-url]: https://www.npmjs.com/package/connect-session-sequelize [connect-session-sequelize-image]: https://img.shields.io/github/stars/mweibel/connect-session-sequelize.svg?label=%E2%98%85 [![★][connect-sqlite3-image] connect-sqlite3][connect-sqlite3-url] A [SQLite3](https://github.com/mapbox/node-sqlite3) session store modeled after the TJ's `connect-redis` store. + [connect-sqlite3-url]: https://www.npmjs.com/package/connect-sqlite3 [connect-sqlite3-image]: https://img.shields.io/github/stars/rawberg/connect-sqlite3.svg?label=%E2%98%85 [![★][express-nedb-session-image] express-nedb-session][express-nedb-session-url] A NeDB-based session store. + [express-nedb-session-url]: https://www.npmjs.com/package/express-nedb-session [express-nedb-session-image]: https://img.shields.io/github/stars/louischatriot/express-nedb-session.svg?label=%E2%98%85 [![★][level-session-store-image] level-session-store][level-session-store-url] A LevelDB-based session store. + [level-session-store-url]: https://www.npmjs.com/package/level-session-store [level-session-store-image]: https://img.shields.io/github/stars/scriptollc/level-session-store.svg?label=%E2%98%85 [![★][mssql-session-store-image] mssql-session-store][mssql-session-store-url] A SQL Server-based session store. + [mssql-session-store-url]: https://www.npmjs.com/package/mssql-session-store [mssql-session-store-image]: https://img.shields.io/github/stars/jwathen/mssql-session-store.svg?label=%E2%98%85 [![★][nedb-session-store-image] nedb-session-store][nedb-session-store-url] An alternate NeDB-based (either in-memory or file-persisted) session store. + [nedb-session-store-url]: https://www.npmjs.com/package/nedb-session-store [nedb-session-store-image]: https://img.shields.io/github/stars/JamesMGreene/nedb-session-store.svg?label=%E2%98%85 [![★][sequelstore-connect-image] sequelstore-connect][sequelstore-connect-url] A session store using [Sequelize.js](http://sequelizejs.com/). + [sequelstore-connect-url]: https://www.npmjs.com/package/sequelstore-connect [sequelstore-connect-image]: https://img.shields.io/github/stars/MattMcFarland/sequelstore-connect.svg?label=%E2%98%85 [![★][session-file-store-image] session-file-store][session-file-store-url] A file system-based session store. + [session-file-store-url]: https://www.npmjs.com/package/session-file-store [session-file-store-image]: https://img.shields.io/github/stars/valery-barysok/session-file-store.svg?label=%E2%98%85 [![★][session-rethinkdb-image] session-rethinkdb][session-rethinkdb-url] A [RethinkDB](http://rethinkdb.com/)-based session store. + [session-rethinkdb-url]: https://www.npmjs.com/package/session-rethinkdb [session-rethinkdb-image]: https://img.shields.io/github/stars/llambda/session-rethinkdb.svg?label=%E2%98%85 From db2a442266cd27c9ce5c32287000f201b567e57f Mon Sep 17 00:00:00 2001 From: Mike Goodwin Date: Sun, 6 Mar 2016 23:00:31 +0000 Subject: [PATCH 03/11] docs: add connect-azuretables to list of session stores closes #285 --- README.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/README.md b/README.md index f2a6df6b..56e47732 100644 --- a/README.md +++ b/README.md @@ -423,6 +423,11 @@ and other multi-core embedded devices). [cluster-store-url]: https://www.npmjs.com/package/cluster-store [cluster-store-image]: https://img.shields.io/github/stars/coolaj86/cluster-store.svg?label=%E2%98%85 +[![★][connect-azuretables-image] connect-azuretables][connect-azuretables-url] An [Azure Table Storage](https://azure.microsoft.com/en-gb/services/storage/tables/)-based session store. + +[connect-azuretables-url]: https://www.npmjs.com/package/connect-azuretables +[connect-azuretables-image]: https://img.shields.io/github/stars/mike-goodwin/connect-azuretables.svg?label=%E2%98%85 + [![★][connect-couchbase-image] connect-couchbase][connect-couchbase-url] A [couchbase](http://www.couchbase.com/)-based session store. [connect-couchbase-url]: https://www.npmjs.com/package/connect-couchbase From 30a3f498203e0cd3b8815713f29e1f8f10f8c34a Mon Sep 17 00:00:00 2001 From: Gabriel Foust Date: Wed, 2 Mar 2016 14:54:08 -0600 Subject: [PATCH 04/11] Methods are no longer enumerable on req.session object closes #282 --- HISTORY.md | 5 +++++ session/session.js | 39 ++++++++++++++++++++++++++++----------- test/session.js | 18 ++++++++++++++++++ 3 files changed, 51 insertions(+), 11 deletions(-) diff --git a/HISTORY.md b/HISTORY.md index ffb63d71..4145b4fd 100644 --- a/HISTORY.md +++ b/HISTORY.md @@ -1,3 +1,8 @@ +unreleased +========== + + * Methods are no longer enumerable on `req.session` object + 1.13.1 / 2016-01-29 =================== diff --git a/session/session.js b/session/session.js index c3c0f15a..2eacde60 100644 --- a/session/session.js +++ b/session/session.js @@ -44,9 +44,9 @@ function Session(req, data) { * @api public */ -Session.prototype.touch = function(){ +defineMethod(Session.prototype, 'touch', function touch() { return this.resetMaxAge(); -}; +}); /** * Reset `.maxAge` to `.originalMaxAge`. @@ -55,10 +55,10 @@ Session.prototype.touch = function(){ * @api public */ -Session.prototype.resetMaxAge = function(){ +defineMethod(Session.prototype, 'resetMaxAge', function resetMaxAge() { this.cookie.maxAge = this.cookie.originalMaxAge; return this; -}; +}); /** * Save the session data with optional callback `fn(err)`. @@ -68,10 +68,10 @@ Session.prototype.resetMaxAge = function(){ * @api public */ -Session.prototype.save = function(fn){ +defineMethod(Session.prototype, 'save', function save(fn) { this.req.sessionStore.set(this.id, this, fn || function(){}); return this; -}; +}); /** * Re-loads the session data _without_ altering @@ -85,7 +85,7 @@ Session.prototype.save = function(fn){ * @api public */ -Session.prototype.reload = function(fn){ +defineMethod(Session.prototype, 'reload', function reload(fn) { var req = this.req , store = this.req.sessionStore; store.get(this.id, function(err, sess){ @@ -95,7 +95,7 @@ Session.prototype.reload = function(fn){ fn(); }); return this; -}; +}); /** * Destroy `this` session. @@ -105,11 +105,11 @@ Session.prototype.reload = function(fn){ * @api public */ -Session.prototype.destroy = function(fn){ +defineMethod(Session.prototype, 'destroy', function destroy(fn) { delete this.req.session; this.req.sessionStore.destroy(this.id, fn); return this; -}; +}); /** * Regenerate this request's session. @@ -119,7 +119,24 @@ Session.prototype.destroy = function(fn){ * @api public */ -Session.prototype.regenerate = function(fn){ +defineMethod(Session.prototype, 'regenerate', function regenerate(fn) { this.req.sessionStore.regenerate(this.req, fn); return this; +}); + +/** + * Helper function for creating a method on a prototype. + * + * @param {Object} obj + * @param {String} name + * @param {Function} fn + * @private + */ +function defineMethod(obj, name, fn) { + Object.defineProperty(obj, name, { + configurable: true, + enumerable: false, + value: fn, + writable: true + }); }; diff --git a/test/session.js b/test/session.js index 682cb8d0..35f20de2 100644 --- a/test/session.js +++ b/test/session.js @@ -1420,6 +1420,24 @@ describe('session()', function(){ }); }) + it('should not have enumerable methods', function (done) { + var app = express() + .use(session({ secret: 'keyboard cat', cookie: { maxAge: min }})) + .use(function(req, res, next) { + req.session.foo = 'foo'; + req.session.bar = 'bar'; + var keys = []; + for (var key in req.session) { + keys.push(key); + } + res.end(keys.sort().join(',')); + }); + + request(app) + .get('/') + .expect(200, 'bar,cookie,foo', done); + }); + describe('.destroy()', function(){ it('should destroy the previous session', function(done){ var app = express() From 005078aaada837d2a57e7324986ead60bf326e84 Mon Sep 17 00:00:00 2001 From: Charles Hill Date: Tue, 2 Feb 2016 16:11:51 +0100 Subject: [PATCH 05/11] docs: add express-mysql-session to list of session stores closes #268 --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index 56e47732..ca9da9d1 100644 --- a/README.md +++ b/README.md @@ -485,6 +485,12 @@ and other multi-core embedded devices). [connect-session-sequelize-url]: https://www.npmjs.com/package/connect-session-sequelize [connect-session-sequelize-image]: https://img.shields.io/github/stars/mweibel/connect-session-sequelize.svg?label=%E2%98%85 +[![★][express-mysql-session-image] express-mysql-session][express-mysql-session-url] A session store using native +[MySQL](https://www.mysql.com/) via the [node-mysql](https://github.com/felixge/node-mysql) module. + +[express-mysql-session-url]: https://www.npmjs.com/package/express-mysql-session +[express-mysql-session-image]: https://img.shields.io/github/stars/chill117/express-mysql-session.svg?label=%E2%98%85 + [![★][connect-sqlite3-image] connect-sqlite3][connect-sqlite3-url] A [SQLite3](https://github.com/mapbox/node-sqlite3) session store modeled after the TJ's `connect-redis` store. [connect-sqlite3-url]: https://www.npmjs.com/package/connect-sqlite3 From 891cfe0fdf5f33330bd61047687db73efd4c162f Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sat, 14 May 2016 23:23:10 +0800 Subject: [PATCH 06/11] complete something --- README.md | 59 +++++++++++++++++++------------------------------------ 1 file changed, 20 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index ca9da9d1..3be8a19f 100644 --- a/README.md +++ b/README.md @@ -6,53 +6,32 @@ [![Test Coverage][coveralls-image]][coveralls-url] [![Gratipay][gratipay-image]][gratipay-url] -## Installation - -```bash -$ npm install express-session +## 安装 +```js + $ npm install express-session ``` - ## API - -```js -var session = require('express-session') ``` + var session = require('express-session') +``` +#### session(配置) +使用相应的配置来创建一个session中间件 -### session(options) - -Create a session middleware with the given `options`. - -**Note** Session data is _not_ saved in the cookie itself, just the session ID. -Session data is stored server-side. - -**Warning** The default server-side session storage, `MemoryStore`, is _purposely_ -not designed for a production environment. It will leak memory under most -conditions, does not scale past a single process, and is meant for debugging and -developing. - -For a list of stores, see [compatible session stores](#compatible-session-stores). - -#### Options - -`express-session` accepts these properties in the options object. - -##### cookie - -Settings for the session ID cookie. See the "Cookie options" section below for -more information on the different values. - -The default value is `{ path: '/', httpOnly: true, secure: false, maxAge: null }`. +**提示** 除了session ID之外,session的数据*不会*自己储存到cookie中,session的数据会被存在服务器端 -##### genid +**警告** 在服务器端session故意默认储存在内存中,这不是为了生产环境而设计的.这样在大多数情况下会泄露内存,does not scale past a single process, and is meant for debugging and developing. -Function to call to generate a new session ID. Provide a function that returns -a string that will be used as a session ID. The function is given `req` as the -first argument if you want to use some value attached to `req` when generating -the ID. +更多的储存列表,详情请看: [compatible session stores](#compatible-session-stores) +#### 配置 +`express-session`在配置对象中可以接受这些属性 +###### cookie +设置cookie中的session ID.cookie更多不同参数的信息,请参考下面"cookie配置"小节,其默认的参数为`{ path: '/', httpOnly: true, secure: false, maxAge: null }` +###### genid +用来生成一个新的session ID的函数,提供一个返回通常用来做session ID的字符串的方法.当生成ID时,你如果想将某些值赋值给`req`,那么`req`作为该方法的第一个参数. -The default value is a function which uses the `uid-safe` library to generate IDs. +该默认值是一个使用`uid-safe`依赖库生成ID的函数. -**NOTE** be careful to generate unique IDs so your sessions do not conflict. +**提示** 注意生成唯一的ID,这样你的session才不会产生冲突 ```js app.use(session({ @@ -63,6 +42,8 @@ app.use(session({ })) ``` +``` + ##### name The name of the session ID cookie to set in the response (and read from in the From 481ea30fbfa9264ae5b93b7b9d155dd6c2eeef44 Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sat, 14 May 2016 23:24:31 +0800 Subject: [PATCH 07/11] complete something --- README.md | 6 ------ 1 file changed, 6 deletions(-) diff --git a/README.md b/README.md index 3be8a19f..92fa9b88 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,5 @@ # express-session -[![NPM Version][npm-image]][npm-url] -[![NPM Downloads][downloads-image]][downloads-url] -[![Build Status][travis-image]][travis-url] -[![Test Coverage][coveralls-image]][coveralls-url] -[![Gratipay][gratipay-image]][gratipay-url] - ## 安装 ```js $ npm install express-session From 8e4e1d18cecaf671a806b8cd935919375102a705 Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sun, 15 May 2016 10:22:20 +0800 Subject: [PATCH 08/11] complete someting --- README.md | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 92fa9b88..bef35b31 100644 --- a/README.md +++ b/README.md @@ -36,31 +36,24 @@ app.use(session({ })) ``` -``` - ##### name -The name of the session ID cookie to set in the response (and read from in the -request). +session ID的cookie名可以在设置在响应头中(可以在请求头中读取). -The default value is `'connect.sid'`. +默认值是 `'connect.sid'`. -**Note** if you have multiple apps running on the same hostname (this is just -the name, i.e. `localhost` or `127.0.0.1`; different schemes and ports do not -name a different hostname), then you need to separate the session cookies from -each other. The simplest method is to simply set different `name`s per app. +**提示**如果你有多个app运行在同一个主机名上(只是主机名相同,比如`localhost`或者`127.0.0.1`;如果有不同的方案和端口的话,就没有必要命名不同的主机名了),这时你需要区分每一个session cookie了.最简单的方法是为每一个app设置一个不同的名称. ##### proxy -Trust the reverse proxy when setting secure cookies (via the "X-Forwarded-Proto" -header). +当设置了安全的cookie后,可以充分相信反向代理(可以通过"X-Forwarded-Proto"头) -The default value is `undefined`. +默认值 `undefined`. - - `true` The "X-Forwarded-Proto" header will be used. - - `false` All headers are ignored and the connection is considered secure only - if there is a direct TLS/SSL connection. - - `undefined` Uses the "trust proxy" setting from express + - `true` 使用 "X-Forwarded-Proto" 头 + - `false` 连接都只考虑安全性,所有的头都会被忽略 + 如果这是一个TLS/SSL连接的话 + - `undefined` 使用express中设置的"trust proxy" ##### resave From 6328353fbd44dc1e06ee89694bba6c7ee5138d64 Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sun, 15 May 2016 10:50:29 +0800 Subject: [PATCH 09/11] complete someting --- README.md | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index bef35b31..d9f03492 100644 --- a/README.md +++ b/README.md @@ -57,12 +57,10 @@ session ID的cookie名可以在设置在响应头中(可以在请求头中读取 ##### resave -Forces the session to be saved back to the session store, even if the session -was never modified during the request. Depending on your store this may be -necessary, but it can also create race conditions where a client makes two -parallel requests to your server and changes made to the session in one -request may get overwritten when the other request ends, even if it made no -changes (this behavior also depends on what store you're using). +Forces the session to be saved back to the session store, even if the sessionwas never modified during the request. Depending on your store this may benecessary, but it can also create race conditions where a client makes twoparallel requests to your server and changes made to the session in onerequest may get overwritten when the other request ends, even if it made nochanges (this behavior also depends on what store you're using). + +即使在请求中session没有进行任何修改,也会强制session重新存储一遍. +可能关键取决于你的存储,但是它会产生一个竞争的情况,当一个客户端向你的服务器发送两条并行的请求时,一个请求中session发生改变时,当另一个请求结束时,这个session可能会被重写,即使这个session没有做任何修改,也可能会被重写(这种情况也取决于你使用的存储). The default value is `true`, but using the default has been deprecated, as the default will change in the future. Please research into this setting From be9ba2f1c0377e31da7af202937a548932bef8d1 Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sun, 15 May 2016 11:37:35 +0800 Subject: [PATCH 10/11] complete someting --- README.md | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/README.md b/README.md index d9f03492..30e5db45 100644 --- a/README.md +++ b/README.md @@ -57,33 +57,20 @@ session ID的cookie名可以在设置在响应头中(可以在请求头中读取 ##### resave -Forces the session to be saved back to the session store, even if the sessionwas never modified during the request. Depending on your store this may benecessary, but it can also create race conditions where a client makes twoparallel requests to your server and changes made to the session in onerequest may get overwritten when the other request ends, even if it made nochanges (this behavior also depends on what store you're using). - 即使在请求中session没有进行任何修改,也会强制session重新存储一遍. -可能关键取决于你的存储,但是它会产生一个竞争的情况,当一个客户端向你的服务器发送两条并行的请求时,一个请求中session发生改变时,当另一个请求结束时,这个session可能会被重写,即使这个session没有做任何修改,也可能会被重写(这种情况也取决于你使用的存储). +取决于你的存储这是非常有必要的,但是它会产生一个竞争的情况,当一个客户端向你的服务器发送两条并行的请求时,一个请求中session发生改变时,当另一个请求结束时,这个session可能会被重写,即使这个session没有做任何修改,也可能会被重写(这种情况也取决于你使用的存储). -The default value is `true`, but using the default has been deprecated, -as the default will change in the future. Please research into this setting -and choose what is appropriate to your use-case. Typically, you'll want -`false`. +默认值是 `true`,但是这个默认值已经被弃用了,这个默认值在之后会被修改.请在研究这个设置后,根据你的使用情况来选择.通常情况下,你会选择`false`. -How do I know if this is necessary for my store? The best way to know is to -check with your store if it implements the `touch` method. If it does, then -you can safely set `resave: false`. If it does not implement the `touch` -method and your store sets an expiration date on stored sessions, then you -likely need `resave: true`. +那我怎么知道,这个是否对我的存储有必要呢?最好的方式是检查你的存储是否有`touch`这个方法.如果有,你可以安全设置`resave:false`.如果没有`touch`这个方法,你的储存会在被存储的session上设置一个过期时间,然后你可能需要`resave:true`. ##### rolling -Force a session identifier cookie to be set on every response. The expiration -is reset to the original [`maxAge`](#cookiemaxage), resetting the expiration -countdown. +会在每一个响应上,强制session设置一个cookie识别码.过期时间会被重置为original [`maxAge`](#cookiemaxage),并且重置倒计时. -The default value is `false`. +默认值是 `false`. -**Note** When this option is set to `true` but the `saveUninitialized` option is -set to `false`, the cookie will not be set on a response with an uninitialized -session. +**提示** 当这个被设置为`true`,但是`saveUninitialized`设置为`false`时,一个响应的session没有被初始化,cookie是不会被设置的. ##### saveUninitialized From 5a10dc4844ceb5b8d5e7ef5cb023956d23971710 Mon Sep 17 00:00:00 2001 From: zhanxin Date: Sun, 15 May 2016 18:00:46 +0800 Subject: [PATCH 11/11] complete something --- README.md | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 30e5db45..a93e351b 100644 --- a/README.md +++ b/README.md @@ -74,21 +74,11 @@ session ID的cookie名可以在设置在响应头中(可以在请求头中读取 ##### saveUninitialized -Forces a session that is "uninitialized" to be saved to the store. A session is -uninitialized when it is new but not modified. Choosing `false` is useful for -implementing login sessions, reducing server storage usage, or complying with -laws that require permission before setting a cookie. Choosing `false` will also -help with race conditions where a client makes multiple parallel requests -without a session. - -The default value is `true`, but using the default has been deprecated, as the -default will change in the future. Please research into this setting and -choose what is appropriate to your use-case. - -**Note** if you are using Session in conjunction with PassportJS, Passport -will add an empty Passport object to the session for use after a user is -authenticated, which will be treated as a modification to the session, causing -it to be saved. +强制将未初始化的session存储到内存中,未初始化的session是指一个全新的session且没有被修改过的.在使用登录session,减少服务器内存的使用,或者遵守在设置cookie前获取许可的规范时,将其设置为`false`是一个不错的选择.而且还能对客户端发送多个没有session请求的所形成竞争情况有所帮助. + +默认值是`true`,但是使用默认值已经被弃用,默认值在之后也将被修改,请研究这个设置之后,根据你的使用情况来选择 + +**提示** 如果你与PassportJS结合使用session的话,在用户认证之后,Passport会增加一个空的Passport对象在session中.这会默认认为session已经被修改,而造成这个session被存储的情况. ##### secret @@ -486,7 +476,7 @@ and other multi-core embedded devices). ## Example -A simple example using `express-session` to store page views for a user. +一个使用`express-session`的简单例子,来演示用户存储一个页面视图. ```js var express = require('express')