You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Get expires `Date` object to be the value for the `Expires Set-Cookie` attribute.
104
-
* By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application.
88
+
* Get expires `date`.
105
89
*
106
90
* @return {Date | undefined}
107
91
* @public
108
92
*/
109
93
110
94
getexpires(){
111
-
returnthis._expires
95
+
returnthis._expires;
112
96
}
113
97
114
98
/**
115
99
* Set expires via max-age in `ms`.
116
100
*
117
-
* @param {number | undefined} ms
101
+
* @param {Number | Date | undefined} ms
118
102
* @public
119
103
*/
120
104
121
105
setmaxAge(ms){
122
-
if(ms!==undefined){
123
-
if(typeofms!=='number'){
124
-
thrownewTypeError('maxAge must be a number')
125
-
}
126
-
this.expires=newDate(Date.now()+ms)
127
-
}else{
128
-
this.expires=undefined
106
+
if(ms&&typeofms!=='number'&&!(msinstanceofDate)){
107
+
thrownewTypeError('maxAge must be a number or Date')
108
+
}
109
+
110
+
if(msinstanceofDate){
111
+
deprecate('maxAge as Date; pass number of milliseconds instead')
129
112
}
113
+
114
+
this.expires=typeofms==='number'
115
+
? newDate(Date.now()+ms)
116
+
: ms;
130
117
}
131
118
132
119
/**
@@ -139,24 +126,23 @@ class Cookie {
139
126
getmaxAge(){
140
127
returnthis.expiresinstanceofDate
141
128
? this.expires.valueOf()-Date.now()
142
-
: this.expires
129
+
: this.expires;
143
130
}
144
131
145
132
/**
146
133
* Return cookie data object.
147
134
*
148
-
* @return {CookieSerializeOptions}
149
-
* @private
135
+
* @this {Cookie & CookieOptions}
136
+
* @return {Object}
137
+
* @public
150
138
*/
151
139
152
140
getdata(){
153
-
if(this.secure==='auto'){
154
-
thrownewError("Invalid runtime state, the Cookie.secure == 'auto', which should not be possible.")
Copy file name to clipboardExpand all lines: session/cookie.types.ts
+12-1Lines changed: 12 additions & 1 deletion
Original file line number
Diff line number
Diff line change
@@ -1,4 +1,4 @@
1
-
exportdeclareinterfaceCookieOptions{
1
+
exportinterfaceCookieOptions{
2
2
/**
3
3
* Specifies the number (in milliseconds) to use when calculating the `Expires Set-Cookie` attribute.
4
4
* This is done by taking the current server time and adding `maxAge` milliseconds to the value to calculate an `Expires` datetime. By default, no maximum age is set.
* Specifies the `Date` object to be the value for the `Expires Set-Cookie` attribute.
43
+
* By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete it on a condition like exiting a web browser application.
44
+
*
45
+
* If both `expires` and `maxAge` are set in the options, then the last one defined in the object is what is used.
46
+
*
47
+
* @deprecated The `expires` option should not be set directly; instead only use the `maxAge` option
48
+
* @see maxAge
49
+
*/
50
+
expires?: Date|null|undefined;
51
+
41
52
/**
42
53
* Specifies the boolean value for the `HttpOnly Set-Cookie` attribute. When truthy, the `HttpOnly` attribute is set, otherwise it is not.
0 commit comments