forked from JacksonTian/ping
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcookie.js
More file actions
executable file
·29 lines (28 loc) · 746 Bytes
/
cookie.js
File metadata and controls
executable file
·29 lines (28 loc) · 746 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
exports.parse = function (cookies) {
var map = {};
var pairs = cookies.split(";");
pairs.forEach(function (pair) {
var kv = pair.split("=");
map[kv[0].trim()] = kv[1] || "";
});
return map;
};
exports.stringify = function (cookie) {
var buffer = [cookie.key, "=", cookie.value];
if (cookie.expires) {
buffer.push("; expires=", (new Date(cookie.expires)).toUTCString());
}
if (cookie.path) {
buffer.push("; path=", cookie.path);
}
if (cookie.domain) {
buffer.push("; domain=", cookie.domain);
}
if (cookie.secure) {
buffer.push("; secure");
}
if (cookie.httpOnly) {
buffer.push("; httponly");
}
return buffer.join("");
};