Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added optional domain parameter to allow control of subdomain scope

  • Loading branch information...
commit 25abdc3a72d24637ebed542d0aff4c4928e6deeb 1 parent dae231f
@richmarr richmarr authored
View
1  README.md
@@ -28,6 +28,7 @@ number of options:
* session_key -- The cookie key name to store the session data in
(default: _node)
* path -- The path to use for the cookie (default: '/')
+ * domain -- (optional) Define a specific domain/subdomain scope for the cookie
## Why store session data in cookies?
View
1  lib/cookie-sessions.js
@@ -57,6 +57,7 @@ var exports = module.exports = function(settings){
+ '; expires=' + exports.expires(s.timeout)
+ '; path=' + s.path + '; HttpOnly';
}
+ if ( s.domain ) cookiestr +='; Domain=' + s.domain;
if (cookiestr !== undefined) {
if(Array.isArray(headers)) headers.push(['Set-Cookie', cookiestr]);
View
5 test/test-cookie-sessions.js
@@ -348,7 +348,8 @@ exports['writeHead'] = function(test){
var s = {
session_key:'_node',
secret: 'secret',
- timeout: 86400
+ timeout: 86400,
+ domain:'.domain.com'
};
var req = {headers: {cookie: "_node="}, url: '/'};
var res = {
@@ -357,7 +358,7 @@ exports['writeHead'] = function(test){
headers['Set-Cookie'],
'_node=serialized_session; ' +
'expires=expiry_date; ' +
- 'path=/; HttpOnly'
+ 'path=/; HttpOnly; Domain=.domain.com'
);
test.equals(headers['original'], 'header');
}
Please sign in to comment.
Something went wrong with that request. Please try again.