forked from expressjs/session
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.js
More file actions
42 lines (32 loc) · 826 Bytes
/
Copy pathutils.js
File metadata and controls
42 lines (32 loc) · 826 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
'use strict'
module.exports.parseSetCookie = parseSetCookie
module.exports.writePatch = writePatch
function parseSetCookie (header) {
var match
var pairs = []
var pattern = /\s*([^=;]+)(?:=([^;]*);?|;|$)/g
while ((match = pattern.exec(header))) {
pairs.push({ name: match[1], value: match[2] })
}
var cookie = pairs.shift()
for (var i = 0; i < pairs.length; i++) {
match = pairs[i]
cookie[match.name.toLowerCase()] = (match.value || true)
}
return cookie
}
function writePatch (res) {
var _end = res.end
var _write = res.write
var ended = false
res.end = function end () {
ended = true
return _end.apply(this, arguments)
}
res.write = function write () {
if (ended) {
throw new Error('write after end')
}
return _write.apply(this, arguments)
}
}