-
-
Notifications
You must be signed in to change notification settings - Fork 153
/
cookie.js
38 lines (28 loc) · 850 Bytes
/
cookie.js
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
module.exports = Cookie
function Cookie(name, value, attrs) {
value || (this.expires = new Date(0))
this.name = name
this.value = value || ""
for (var name in attrs) this[name] = attrs[name]
}
Cookie.prototype = {
path: "/",
expires: undefined,
domain: undefined,
httpOnly: true,
secure: false,
overwrite: true,
toString: function() {
return this.name + "=" + this.value
},
toHeader: function() {
var header = this.toString()
if (this.maxage) this.expires = new Date(Date.now() + this.maxage);
if (this.path ) header += "; path=" + this.path
if (this.expires ) header += "; expires=" + this.expires.toUTCString()
if (this.domain ) header += "; domain=" + this.domain
if (this.secure ) header += "; secure"
if (this.httpOnly ) header += "; httponly"
return header
}
}