2 * Connect - session - Cookie
3 * Copyright(c) 2010 Sencha Inc.
4 * Copyright(c) 2011 TJ Holowaychuk
11 * Module dependencies.
14 var cookie = require('cookie')
15 var deprecate = require('depd')('express-session')
18 * Initialize a new `Cookie` with the given `options`.
20 * @param {IncomingMessage} req
21 * @param {Object} options
25 var Cookie = module.exports = function Cookie(options) {
31 if (typeof options !== 'object') {
32 throw new TypeError('argument options must be a object')
35 for (var key in options) {
37 this[key] = options[key]
42 if (this.originalMaxAge === undefined || this.originalMaxAge === null) {
43 this.originalMaxAge = this.maxAge
62 this.originalMaxAge = this.maxAge;
77 * Set expires via max-age in `ms`.
84 if (ms && typeof ms !== 'number' && !(ms instanceof Date)) {
85 throw new TypeError('maxAge must be a number or Date')
88 if (ms instanceof Date) {
89 deprecate('maxAge as Date; pass number of milliseconds instead')
92 this.expires = typeof ms === 'number'
93 ? new Date(Date.now() + ms)
98 * Get expires max-age in `ms`.
105 return this.expires instanceof Date
106 ? this.expires.valueOf() - Date.now()
111 * Return cookie data object.
119 originalMaxAge: this.originalMaxAge
120 , expires: this._expires
121 , secure: this.secure
122 , httpOnly: this.httpOnly
123 , domain: this.domain
125 , sameSite: this.sameSite
130 * Return a serialized cookie string.
136 serialize: function(name, val){
137 return cookie.serialize(name, val, this.data);
141 * Return JSON representation of this cookie.