tough-cookie 0.9.15 → 0.12.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/.jshintrc CHANGED
@@ -1,72 +1,70 @@
1
1
  {
2
- // Settings
3
- "passfail" : false, // Stop on first error.
4
- "maxerr" : 100, // Maximum error before stopping.
2
+ "passfail" : false,
3
+ "maxerr" : 100,
5
4
 
6
-
7
- // Predefined globals whom JSHint will ignore.
8
- "browser" : false, // Standard browser globals e.g. `window`, `document`.
5
+ "browser" : false,
9
6
  "node" : true,
10
7
  "rhino" : false,
11
8
  "couch" : false,
12
- "wsh" : false, // Windows Scripting Host.
9
+ "wsh" : false,
13
10
 
14
11
  "jquery" : false,
15
12
  "prototypejs" : false,
16
13
  "mootools" : false,
17
14
  "dojo" : false,
18
15
 
19
- "predef" : [ // Custom globals.
20
- "escape", "unescape" // aren't picked up by node flag above :/
21
- ],
22
-
23
-
24
- // Development.
25
- "debug" : false, // Allow debugger statements e.g. browser breakpoints.
26
- "devel" : false, // Allow developments statements e.g. `console.log();`.
16
+ "debug" : false,
17
+ "devel" : false,
27
18
 
19
+ "esnext" : true,
20
+ "strict" : true,
21
+ "globalstrict" : true,
28
22
 
29
- // EcmaScript 5.
30
- "es5" : true, // Allow EcmaScript 5 syntax.
31
- "esnext" : true, // Allow ES "next" syntax, specifically 'const' (V8 has this)
32
- "strict" : false, // Require `use strict` pragma in every file.
33
- "globalstrict" : false, // Allow global "use strict" (also enables 'strict').
23
+ "asi" : false,
24
+ "laxbreak" : false,
25
+ "bitwise" : true,
26
+ "boss" : false,
27
+ "curly" : true,
28
+ "eqeqeq" : false,
29
+ "eqnull" : true,
30
+ "evil" : false,
31
+ "expr" : false,
32
+ "forin" : false,
33
+ "immed" : true,
34
+ "lastsemic" : true,
35
+ "latedef" : false,
36
+ "loopfunc" : false,
37
+ "noarg" : true,
38
+ "regexp" : false,
39
+ "regexdash" : false,
40
+ "scripturl" : false,
41
+ "shadow" : false,
42
+ "supernew" : false,
43
+ "undef" : true,
44
+ "unused" : true,
34
45
 
46
+ "newcap" : true,
47
+ "noempty" : true,
48
+ "nonew" : true,
49
+ "nomen" : false,
50
+ "onevar" : false,
51
+ "onecase" : true,
52
+ "plusplus" : false,
53
+ "proto" : false,
54
+ "sub" : true,
55
+ "trailing" : true,
56
+ "white" : false,
35
57
 
36
- // The Good Parts.
37
- "asi" : false, // Tolerate Automatic Semicolon Insertion (no semicolons).
38
- "laxbreak" : false, // Tolerate unsafe line breaks e.g. `return [\n] x` without semicolons.
39
- "bitwise" : true, // Prohibit bitwise operators (&, |, ^, etc.).
40
- "boss" : false, // Tolerate assignments inside if, for & while. Usually conditions & loops are for comparison, not assignments.
41
- "curly" : false, // Require {} for every new block or scope.
42
- "eqeqeq" : false, // Require triple equals i.e. `===`.
43
- "eqnull" : true, // Tolerate use of `== null`.
44
- "evil" : false, // Tolerate use of `eval`.
45
- "expr" : true, // Tolerate `ExpressionStatement` as Programs.
46
- "forin" : false, // Tolerate `for in` loops without `hasOwnPrototype`.
47
- "immed" : true, // Require immediate invocations to be wrapped in parens e.g. `( function(){}() );`
48
- "latedef" : false, // Prohibit variable use before definition.
49
- "loopfunc" : false, // Allow functions to be defined within loops.
50
- "noarg" : true, // Prohibit use of `arguments.caller` and `arguments.callee`.
51
- "regexp" : true, // Prohibit `.` and `[^...]` in regular expressions.
52
- "regexdash" : false, // Tolerate unescaped last dash i.e. `[-...]`.
53
- "scripturl" : true, // Tolerate script-targeted URLs.
54
- "shadow" : false, // Allows re-define variables later in code e.g. `var x=1; x=2;`.
55
- "supernew" : false, // Tolerate `new function () { ... };` and `new Object;`.
56
- "undef" : true, // Require all non-global variables be declared before they are used.
57
-
58
-
59
- // Personal styling prefrences.
60
- "lastsemic" : true, // Prohibit missing semicolon for the last statement in a one-line block
61
- "newcap" : false, // Require capitalization of all constructor functions e.g. `new F()`.
62
- "noempty" : true, // Prohipit use of empty blocks.
63
- "nonew" : true, // Prohibit use of constructors for side-effects.
64
- "nomen" : false, // Prohibit use of initial or trailing underbars in names.
65
- "onevar" : false, // Allow only one `var` statement per function.
66
- "onecase" : false, // Allow switches with one case statement
67
- "plusplus" : false, // Prohibit use of `++` & `--`.
68
- "proto" : false, // Allow use of __proto__
69
- "sub" : true, // Tolerate all forms of subscript notation besides dot notation e.g. `dict['key']` instead of `dict.key`.
70
- "trailing" : true, // Prohibit trailing whitespaces.
71
- "white" : false // Check against strict whitespace and indentation rules.
58
+ "predef": [
59
+ "describe",
60
+ "it",
61
+ "before",
62
+ "beforeEach",
63
+ "after",
64
+ "afterEach",
65
+ "expect",
66
+ "setTimeout",
67
+ "clearTimeout"
68
+ ],
69
+ "maxlen": 0
72
70
  }
package/.travis.yml ADDED
@@ -0,0 +1,8 @@
1
+ language: node_js
2
+ node_js:
3
+ - "0.10"
4
+ - "0.11"
5
+ matrix:
6
+ fast_finish: true
7
+ allow_failures:
8
+ - node_js: 0.11
package/README.md CHANGED
@@ -2,16 +2,21 @@
2
2
 
3
3
  ![Tough Cookie](http://www.goinstant.com.s3.amazonaws.com/tough-cookie.jpg)
4
4
 
5
+ [![Build Status](https://travis-ci.org/goinstant/node-cookie.png?branch=master)](https://travis-ci.org/goinstant/node-cookie)
6
+
7
+ [![NPM Stats](https://nodei.co/npm/tough-cookie.png?downloads=true&stars=true)](https://npmjs.org/package/tough-cookie)
8
+ ![NPM Downloads](https://nodei.co/npm-dl/tough-cookie.png?months=9)
9
+
5
10
  # Synopsis
6
11
 
7
12
  ``` javascript
8
- var cookies = require('tough-cookie'); // note: not 'cookie', 'cookies' or 'node-cookie'
9
- var Cookie = cookies.Cookie;
13
+ var tough = require('tough-cookie'); // note: not 'cookie', 'cookies' or 'node-cookie'
14
+ var Cookie = tough.Cookie;
10
15
  var cookie = Cookie.parse(header);
11
16
  cookie.value = 'somethingdifferent';
12
17
  header = cookie.toString();
13
18
 
14
- var cookiejar = new cookies.CookieJar();
19
+ var cookiejar = new tough.CookieJar();
15
20
  cookiejar.setCookie(cookie, 'http://currentdomain.example.com/path', cb);
16
21
  // ...
17
22
  cookiejar.getCookies('http://example.com/otherpath',function(err,cookies) {
@@ -31,8 +36,8 @@ Why the name? NPM modules `cookie`, `cookies` and `cookiejar` were already take
31
36
 
32
37
  # API
33
38
 
34
- cookies
35
- =======
39
+ tough
40
+ =====
36
41
 
37
42
  Functions on the module you get from `require('tough-cookie')`. All can be used as pure functions and don't need to be "bound".
38
43
 
@@ -124,7 +129,7 @@ Here's how to process the Set-Cookie header(s) on a node HTTP/HTTPS response:
124
129
 
125
130
  ``` javascript
126
131
  if (res.headers['set-cookie'] instanceof Array)
127
- cookies = res.headers['set-cookie'].map(Cookie.parse);
132
+ cookies = res.headers['set-cookie'].map(function (c) { return (Cookie.parse(c)); });
128
133
  else
129
134
  cookies = [Cookie.parse(res.headers['set-cookie'])];
130
135
  ```
@@ -146,7 +151,7 @@ Properties
146
151
  * _secure_ - boolean - the `Secure` cookie flag
147
152
  * _httpOnly_ - boolean - the `HttpOnly` cookie flag
148
153
  * _extensions_ - `Array` - any unrecognized cookie attributes as strings (even if equal-signs inside)
149
-
154
+
150
155
  After a cookie has been passed through `CookieJar.setCookie()` it will have the following additional attributes:
151
156
 
152
157
  * _hostOnly_ - boolean - is this a host-only cookie (i.e. no Domain field was set, but was instead implied)
@@ -236,7 +241,7 @@ Attributes
236
241
  ----------
237
242
 
238
243
  * _rejectPublicSuffixes_ - boolean - reject cookies with domains like "com" and "co.uk" (default: `true`)
239
-
244
+
240
245
  Since eventually this module would like to support database/remote/etc. CookieJars, continuation passing style is used for CookieJar methods.
241
246
 
242
247
  .setCookie(cookieOrString, currentUrl, [{options},] cb(err,cookie))
@@ -254,11 +259,16 @@ The `options` object can be omitted and can have the following properties:
254
259
 
255
260
  As per the RFC, the `.hostOnly` property is set if there was no "Domain=" parameter in the cookie string (or `.domain` was null on the Cookie object). The `.domain` property is set to the fully-qualified hostname of `currentUrl` in this case. Matching this cookie requires an exact hostname match (not a `domainMatch` as per usual).
256
261
 
262
+ .setCookieSync(cookieOrString, currentUrl, [{options}])
263
+ -------------------------------------------------------
264
+
265
+ Synchronous version of `setCookie`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
266
+
257
267
  .storeCookie(cookie, [{options},] cb(err,cookie))
258
268
  -------------------------------------------------
259
269
 
260
270
  __REMOVED__ removed in lieu of the CookieStore API below
261
-
271
+
262
272
  .getCookies(currentUrl, [{options},] cb(err,cookies))
263
273
  -----------------------------------------------------
264
274
 
@@ -276,20 +286,42 @@ The `options` object can be omitted and can have the following properties:
276
286
 
277
287
  The `.lastAccessed` property of the returned cookies will have been updated.
278
288
 
289
+ .getCookiesSync(currentUrl, [{options}])
290
+ ----------------------------------------
291
+
292
+ Synchronous version of `getCookies`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
293
+
279
294
  .getCookieString(...)
280
295
  ---------------------
281
296
 
282
297
  Accepts the same options as `.getCookies()` but passes a string suitable for a Cookie header rather than an array to the callback. Simply maps the `Cookie` array via `.cookieString()`.
283
298
 
299
+ .getCookieStringSync(...)
300
+ -------------------------
301
+
302
+ Synchronous version of `getCookieString`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
303
+
284
304
  .getSetCookieStrings(...)
285
305
  -------------------------
286
306
 
287
- Accepts the same options as `.getCookies()` but passes an array of strings suitable for Set-Cookie headers (rather than an array of `Cookie`s) to the callback. Simply maps the cookie array via `.toString()`.
307
+ Returns an array of strings suitable for **Set-Cookie** headers. Accepts the same options as `.getCookies()`. Simply maps the cookie array via `.toString()`.
308
+
309
+ .getSetCookieStringsSync(...)
310
+ -----------------------------
311
+
312
+ Synchronous version of `getSetCookieStrings`; only works with synchronous stores (e.g. the default `MemoryCookieStore`).
313
+
314
+ Store
315
+ =====
316
+
317
+ Base class for CookieJar stores.
288
318
 
289
319
  # CookieStore API
290
320
 
291
321
  The storage model for each `CookieJar` instance can be replaced with a custom implementation. The default is `MemoryCookieStore` which can be found in the `lib/memstore.js` file. The API uses continuation-passing-style to allow for asynchronous stores.
292
322
 
323
+ Stores should inherit from the base `Store` class, which is available as `require('tough-cookie').Store`. Stores are asynchronous by default, but if `store.synchronous` is set, then the `*Sync` methods on the CookieJar can be used.
324
+
293
325
  All `domain` parameters will have been normalized before calling.
294
326
 
295
327
  The Cookie store must have all of the following methods.
@@ -358,7 +390,7 @@ Pass an error ONLY if removing any existing cookies failed.
358
390
 
359
391
  (tl;dr: MIT with some MPL/1.1)
360
392
 
361
- Copyright GoInstant, Inc. and other contributors. All rights reserved.
393
+ Copyright 2012- GoInstant, Inc. and other contributors. All rights reserved.
362
394
  Permission is hereby granted, free of charge, to any person obtaining a copy
363
395
  of this software and associated documentation files (the "Software"), to
364
396
  deal in the Software without restriction, including without limitation the
@@ -18,13 +18,15 @@
18
18
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19
19
  * IN THE SOFTWARE.
20
20
  */
21
-
21
+ 'use strict';
22
22
  var fs = require('fs');
23
23
  var assert = require('assert');
24
24
  var punycode = require('punycode');
25
25
 
26
26
  fs.readFile('./public-suffix.txt', 'utf8', function(err,string) {
27
- if (err) throw err;
27
+ if (err) {
28
+ throw err;
29
+ }
28
30
  var lines = string.split("\n");
29
31
  process.nextTick(function() {
30
32
  processList(lines);
@@ -38,7 +40,9 @@ function processList(lines) {
38
40
  while (lines.length) {
39
41
  var line = lines.shift();
40
42
  line = line.replace(COMMENT,'').trim();
41
- if (!line) continue;
43
+ if (!line) {
44
+ continue;
45
+ }
42
46
  addToIndex(index,line);
43
47
  }
44
48
 
@@ -47,7 +51,7 @@ function processList(lines) {
47
51
  var w = fs.createWriteStream('./lib/pubsuffix.js',{
48
52
  flags: 'w',
49
53
  encoding: 'utf8',
50
- mode: 0644,
54
+ mode: parseInt('644',8)
51
55
  });
52
56
  w.on('end', process.exit);
53
57
  w.write("/****************************************************\n");
@@ -76,11 +80,12 @@ function addToIndex(index,line) {
76
80
  line = line.slice(prefix.length);
77
81
  }
78
82
  line = prefix + punycode.toASCII(line);
79
-
80
- if (line.substr(0,1) == '!')
83
+
84
+ if (line.substr(0,1) == '!') {
81
85
  index[line.substr(1)] = false;
82
- else
86
+ } else {
83
87
  index[line] = true;
88
+ }
84
89
  }
85
90
 
86
91
  // include the licence in the function since it gets written to pubsuffix.js
@@ -105,8 +110,12 @@ function getPublicSuffix(domain) {
105
110
  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
106
111
  * IN THE SOFTWARE.
107
112
  */
108
- if (!domain) return null;
109
- if (domain.match(/^\./)) return null;
113
+ if (!domain) {
114
+ return null;
115
+ }
116
+ if (domain.match(/^\./)) {
117
+ return null;
118
+ }
110
119
 
111
120
  domain = domain.toLowerCase();
112
121
  var parts = domain.split('.').reverse();