Comparing version 0.0.2 to 0.0.3
@@ -21,3 +21,5 @@ | ||
function getCookie(name) { | ||
function getCookie(name, opts) { | ||
opts = opts || {} | ||
var req = this | ||
@@ -27,3 +29,15 @@ , junks = ("; " + req.headers.cookie).split("; " + name + "=") | ||
if (junks.length > 2) { | ||
throw new Error("Cookie fixation detected") | ||
;(opts.path || "").split("/").map(function(val, key, arr) { | ||
var path = arr.slice(0, key+1).join("/") | ||
, domain = opts.domain | ||
req.res.cookie(name, "", {ttl: -1, path: path}) | ||
if (domain) { | ||
req.res.cookie(name, "", {ttl: -1, path: path, domain: domain}) | ||
if (domain !== (domain = domain.replace(/^[^.]+/, "*"))) { | ||
req.res.cookie(name, "", {ttl: -1, path: path, domain: domain}) | ||
} | ||
} | ||
}) | ||
throw new Error("Cookie fixation detected: " + req.headers.cookie) | ||
} | ||
@@ -30,0 +44,0 @@ |
{ | ||
"name": "app-lite", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"stability": 1, | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
90
util.js
exports.lineEmitter = lineEmitter | ||
exports.uuid4 = uuid4 | ||
exports.rand = rand | ||
exports.wait = wait | ||
exports.Storage = Storage | ||
// Usage: | ||
// var client = net.connect(soc) | ||
// .on("line", function(line) {}) | ||
// lineEmitter(client) | ||
function lineEmitter(emitter, opts) { | ||
opts = opts || {} | ||
var leftover = "" | ||
, separator = opts.separator || /\r?\n/ | ||
, emit = opts.emit || "line" | ||
, listen = opts.listen || "data" | ||
, end = opts.end || "end" | ||
emitter | ||
.on(listen, lineEmitterData) | ||
.on(end, lineEmitterEnd) | ||
function lineEmitterData(data){ | ||
var lines = (leftover + data).split(separator) | ||
// keep the last partial line buffered | ||
leftover = lines.pop() | ||
for (var i = 0, len = lines.length; i < len; ) { | ||
this.emit(emit, lines[i++]) | ||
} | ||
} | ||
function lineEmitterEnd() { | ||
if (leftover) { | ||
this.emit(emit, leftover) | ||
} | ||
leftover = "" | ||
emitter | ||
.removeListener(listen, lineEmitterData) | ||
.removeListener(end, lineEmitterEnd) | ||
} | ||
return emitter | ||
} | ||
function uuid4(a, b) { | ||
@@ -14,3 +57,3 @@ for (a = b = ""; a++ < 36; ) { | ||
for (var out = ""; out.length < len; ) { | ||
out += (Date.now() * Math.random()).toString(36).slice(0, 6) | ||
out += (Date.now() * Math.random()).toString(36).split(".")[0] | ||
} | ||
@@ -20,2 +63,47 @@ return out.slice(-len) | ||
function wait(fn, _pending) { | ||
var pending = _pending || 0 | ||
, result = [null] | ||
function resume() { | ||
if (!--pending && fn) { | ||
fn.apply(this, result) | ||
} | ||
} | ||
resume.wait = function(pos) { | ||
++pending | ||
if (pos === void 0) pos = pending | ||
return function(err, res) { | ||
if (err) { | ||
fn.call(this, err) | ||
} else { | ||
result[pos] = res | ||
resume() | ||
} | ||
} | ||
} | ||
return resume | ||
} | ||
function Storage() { | ||
this.data = {} | ||
} | ||
Storage.prototype = { | ||
get: function(key, next) { | ||
var obj = this.data[key] | ||
, err = obj ? null : "Item not found" | ||
next(err, obj) | ||
}, | ||
set: function(key, val, next) { | ||
this.data[key] = val | ||
next(null) | ||
}, | ||
rename: function(key, newKey, next) { | ||
this.data[newKey] = this.data[key] | ||
delete this.data[key] | ||
next(null) | ||
} | ||
} | ||
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19359
629