Skip to content
This repository has been archived by the owner on Feb 3, 2020. It is now read-only.

Commit

Permalink
Merge pull request #20 from richmarr/master
Browse files Browse the repository at this point in the history
Added domain option
  • Loading branch information
Caolan McMahon committed Feb 13, 2012
2 parents dae231f + 25abdc3 commit 12f63d4
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -28,6 +28,7 @@ number of options:
* session_key -- The cookie key name to store the session data in * session_key -- The cookie key name to store the session data in
(default: _node) (default: _node)
* path -- The path to use for the cookie (default: '/') * 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? ## Why store session data in cookies?
Expand Down
1 change: 1 addition & 0 deletions lib/cookie-sessions.js
Expand Up @@ -57,6 +57,7 @@ var exports = module.exports = function(settings){
+ '; expires=' + exports.expires(s.timeout) + '; expires=' + exports.expires(s.timeout)
+ '; path=' + s.path + '; HttpOnly'; + '; path=' + s.path + '; HttpOnly';
} }
if ( s.domain ) cookiestr +='; Domain=' + s.domain;


if (cookiestr !== undefined) { if (cookiestr !== undefined) {
if(Array.isArray(headers)) headers.push(['Set-Cookie', cookiestr]); if(Array.isArray(headers)) headers.push(['Set-Cookie', cookiestr]);
Expand Down
5 changes: 3 additions & 2 deletions test/test-cookie-sessions.js
Expand Up @@ -348,7 +348,8 @@ exports['writeHead'] = function(test){
var s = { var s = {
session_key:'_node', session_key:'_node',
secret: 'secret', secret: 'secret',
timeout: 86400 timeout: 86400,
domain:'.domain.com'
}; };
var req = {headers: {cookie: "_node="}, url: '/'}; var req = {headers: {cookie: "_node="}, url: '/'};
var res = { var res = {
Expand All @@ -357,7 +358,7 @@ exports['writeHead'] = function(test){
headers['Set-Cookie'], headers['Set-Cookie'],
'_node=serialized_session; ' + '_node=serialized_session; ' +
'expires=expiry_date; ' + 'expires=expiry_date; ' +
'path=/; HttpOnly' 'path=/; HttpOnly; Domain=.domain.com'
); );
test.equals(headers['original'], 'header'); test.equals(headers['original'], 'header');
} }
Expand Down

0 comments on commit 12f63d4

Please sign in to comment.