Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Moved parseCookie to a different location.
  • Loading branch information
steveWang committed Aug 7, 2011
1 parent c6b48b6 commit 5f5b942
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 16 deletions.
14 changes: 14 additions & 0 deletions lib/nowUtil.js
Expand Up @@ -19,6 +19,20 @@ Object.defineProperty(Array.prototype,
});

var util = {
parseCookie: function (cookie) {
if (typeof cookie !== 'string') {
return {};
}
var regex = /([^=\s]+)=(.*?)[;$]/g;
var match = cookie.match(regex);
var jsonCookie = {};
var index;
for (var i = 0; i < match.length; i++) {
index = match[i].indexOf('=');
jsonCookie[match[i].substring(0, index)] = match[i].substring(index + 1, match[i].length - 1);
}
return jsonCookie;
},

hasProperty: function (obj, prop) {
return Object.prototype.hasOwnProperty.call(Object(obj), prop);
Expand Down
17 changes: 1 addition & 16 deletions lib/user.js
Expand Up @@ -2,21 +2,6 @@ var nowUtil = require('./nowUtil.js').nowUtil;
var Proxy = require('./proxy');
var ScopeTable = require('./scopeTable').ScopeTable;

function parseCookie(cookie) {
if (typeof cookie !== 'string') {
return {};
}
var regex = /([^=\s]+)=(.*?)[;$]/g;
var match = cookie.match(regex);
var jsonCookie = {};
var index;
for (var i = 0; i < match.length; i++) {
index = match[i].indexOf('=');
jsonCookie[match[i].substring(0, index)] = match[i].substring(index + 1, match[i].length - 1);
}
return jsonCookie;
}

exports.initialize = function (nowjs) {
var fn = require('./function').init(nowjs);

Expand Down Expand Up @@ -64,7 +49,7 @@ exports.initialize = function (nowjs) {
* @property {String} cookie The user's cookie, as determined by
* Socket.IO.
*/
this.user = { clientId: socket.id, cookie: parseCookie(socket.handshake.headers.cookie) };
this.user = { clientId: socket.id, cookie: nowUtil.parseCookie(socket.handshake.headers.cookie) };

// set to true upon first replaceVar and emit connect event
/**
Expand Down

0 comments on commit 5f5b942

Please sign in to comment.