• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

expressjs / session / 676 / 10

Source File

100.0
/session/cookie.js
1
/*!
2
 * Connect - session - Cookie
3
 * Copyright(c) 2010 Sencha Inc.
4
 * Copyright(c) 2011 TJ Holowaychuk
5
 * MIT Licensed
6
 */
7

8
'use strict';
9

10
/**
11
 * Module dependencies.
12
 */
13

14
var merge = require('utils-merge')
1✔
15
  , cookie = require('cookie');
16

17
/**
18
 * Initialize a new `Cookie` with the given `options`.
19
 *
20
 * @param {IncomingMessage} req
21
 * @param {Object} options
22
 * @api private
23
 */
24

25
var Cookie = module.exports = function Cookie(options) {
1✔
26
  this.path = '/';
148✔
27
  this.maxAge = null;
148✔
28
  this.httpOnly = true;
148✔
29
  if (options) merge(this, options);
148✔
30
  this.originalMaxAge = undefined == this.originalMaxAge
148✔
31
    ? this.maxAge
32
    : this.originalMaxAge;
33
};
34

35
/*!
36
 * Prototype.
37
 */
38

39
Cookie.prototype = {
1✔
40

41
  /**
42
   * Set expires `date`.
43
   *
44
   * @param {Date} date
45
   * @api public
46
   */
47

48
  set expires(date) {
49
    this._expires = date;
451✔
50
    this.originalMaxAge = this.maxAge;
451✔
51
  },
52

53
  /**
54
   * Get expires `date`.
55
   *
56
   * @return {Date}
57
   * @api public
58
   */
59

60
  get expires() {
61
    return this._expires;
983✔
62
  },
63

64
  /**
65
   * Set expires via max-age in `ms`.
66
   *
67
   * @param {Number} ms
68
   * @api public
69
   */
70

71
  set maxAge(ms) {
72
    this.expires = 'number' == typeof ms
380✔
73
      ? new Date(Date.now() + ms)
74
      : ms;
75
  },
76

77
  /**
78
   * Get expires max-age in `ms`.
79
   *
80
   * @return {Number}
81
   * @api public
82
   */
83

84
  get maxAge() {
85
    return this.expires instanceof Date
478✔
86
      ? this.expires.valueOf() - Date.now()
87
      : this.expires;
88
  },
89

90
  /**
91
   * Return cookie data object.
92
   *
93
   * @return {Object}
94
   * @api private
95
   */
96

97
  get data() {
98
    return {
678✔
99
        originalMaxAge: this.originalMaxAge
100
      , expires: this._expires
101
      , secure: this.secure
102
      , httpOnly: this.httpOnly
103
      , domain: this.domain
104
      , path: this.path
105
      , sameSite: this.sameSite
106
    }
107
  },
108

109
  /**
110
   * Return a serialized cookie string.
111
   *
112
   * @return {String}
113
   * @api public
114
   */
115

116
  serialize: function(name, val){
117
    return cookie.serialize(name, val, this.data);
1✔
118
  },
119

120
  /**
121
   * Return JSON representation of this cookie.
122
   *
123
   * @return {Object}
124
   * @api private
125
   */
126

127
  toJSON: function(){
128
    return this.data;
568✔
129
  }
130
};
  • Back to Build 676
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc