superagent 2.0.0 → 2.3.0

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/.travis.yml CHANGED
@@ -1,11 +1,10 @@
1
1
  sudo: false
2
2
  language: node_js
3
3
  node_js:
4
- - "5.4"
5
- - "4.2"
4
+ - "6.2"
5
+ - "4.4"
6
6
  - "0.12"
7
7
  - "0.10"
8
- - "iojs"
9
8
 
10
9
  env:
11
10
  global:
@@ -14,5 +13,5 @@ env:
14
13
 
15
14
  matrix:
16
15
  include:
17
- - node_js: "4.2"
16
+ - node_js: "4.4"
18
17
  env: BROWSER=1
package/History.md CHANGED
@@ -1,3 +1,23 @@
1
+ # 2.3.0
2
+
3
+ * Enabled `.field()` to handle objects (Affan Shahid)
4
+ * Added authentication with client certificates (terusus)
5
+ * Added `.catch()` for more Promise-like interface (Maxim Samoilov, Kornel Lesiński)
6
+ * Silenced errors from incomplete gzip streams for compatibility with web browsers (Kornel Lesiński)
7
+ * Fixed `event.direction` in uploads (Kornel Lesiński)
8
+ * Fixed returned value of overwritten response object's `on()` method (Juan Dopazo)
9
+
10
+ # 2.2.0
11
+
12
+ * Added `timedout` property to node Request instance (Alexander Pope)
13
+ * Unified `null` querystring values in node and browser environments. (George Chung)
14
+
15
+ # 2.1.0
16
+
17
+ * Refactored async parsers. Now the `end` callback waits for async parsers to finish (Kornel Lesiński)
18
+ * Errors thrown in `.end()` callback don't cause the callback to be called twice (Kornel Lesiński)
19
+ * Added `headers` to `toJSON()` (Tao)
20
+
1
21
  # 2.0.0
2
22
 
3
23
  ## Breaking changes
package/Readme.md CHANGED
@@ -1,6 +1,4 @@
1
- # SuperAgent [![Build Status](https://travis-ci.org/visionmedia/superagent.svg?branch=master)](https://travis-ci.org/visionmedia/superagent)
2
-
3
- [![Sauce Test Status](https://saucelabs.com/browser-matrix/shtylman-superagent.svg)](https://saucelabs.com/u/shtylman-superagent)
1
+ # SuperAgent
4
2
 
5
3
  SuperAgent is a small progressive __client-side__ HTTP request library, and __Node.js__ module with the same API, sporting many high-level HTTP client features. View the [docs](http://visionmedia.github.io/superagent/).
6
4
 
@@ -20,7 +18,7 @@ component:
20
18
  $ component install visionmedia/superagent
21
19
  ```
22
20
 
23
- Works with [browserify](https://github.com/substack/node-browserify) and should work with [webpack](https://github.com/visionmedia/superagent/wiki/Superagent-for-Webpack)
21
+ Works with [browserify](https://github.com/substack/node-browserify) and should work with [webpack](https://github.com/visionmedia/superagent/wiki/SuperAgent-for-Webpack)
24
22
 
25
23
  ```js
26
24
  request
@@ -48,7 +46,7 @@ Even though IE9 is supported, a polyfill for `window.FormData` is required for `
48
46
 
49
47
  # Plugins
50
48
 
51
- Superagent is easily extended via plugins.
49
+ SuperAgent is easily extended via plugins.
52
50
 
53
51
  ```js
54
52
  var nocache = require('superagent-no-cache');
@@ -70,17 +68,17 @@ Existing plugins:
70
68
  * [superagent-suffix](https://github.com/timneutkens1/superagent-suffix) - suffix URLs with a given path
71
69
  * [superagent-mock](https://github.com/M6Web/superagent-mock) - simulate HTTP calls by returning data fixtures based on the requested URL
72
70
  * [superagent-mocker](https://github.com/shuvalov-anton/superagent-mocker) — simulate REST API
73
- * [superagent-cache](https://github.com/jpodwys/superagent-cache) - superagent with built-in, flexible caching
71
+ * [superagent-cache](https://github.com/jpodwys/superagent-cache) - SuperAgent with built-in, flexible caching (compatible with SuperAgent `1.x`)
74
72
  * [superagent-jsonapify](https://github.com/alex94puchades/superagent-jsonapify) - A lightweight [json-api](http://jsonapi.org/format/) client addon for superagent
75
73
  * [superagent-serializer](https://github.com/zzarcon/superagent-serializer) - Converts server payload into different cases
76
- * [superagent-promise-plugin](https://github.com/jomaxx/superagent-promise-plugin) - Shims req.end to return a promise when executed with no callback.
77
74
  * [superagent-use](https://github.com/koenpunt/superagent-use) - A client addon to apply plugins to all requests.
78
75
  * [superagent-httpbackend](https://www.npmjs.com/package/superagent-httpbackend) - stub out requests using AngularJS' $httpBackend syntax
79
76
  * [superagent-throttle](https://github.com/leviwheatcroft/superagent-throttle) - queues and intelligently throttles requests
77
+ * [superagent-charset](https://github.com/magicdawn/superagent-charset) - add charset support for node's SuperAgent
80
78
 
81
79
  Please prefix your plugin with `superagent-*` so that it can easily be found by others.
82
80
 
83
- For superagent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki).
81
+ For SuperAgent extensions such as couchdb and oauth visit the [wiki](https://github.com/visionmedia/superagent/wiki).
84
82
 
85
83
  ## Running node tests
86
84
 
@@ -120,7 +118,7 @@ Edit tests and refresh your browser. You do not have to restart the test runner.
120
118
 
121
119
  **npm (for browser standalone)** When we publish versions to npm, we run `make superagent.js` which generates the standalone `superagent.js` file via `browserify`, and this file is included in the package published to npm (but this file is never checked into the git repository). If users want to install via npm but serve a single `.js` file directly to the browser, the `node_modules/superagent/superagent.js` is a standalone browserified file ready to go for that purpose. It is not minified.
122
120
 
123
- **npm (for browserify)** is handled via the `package.json` `browser` field which allows users to install superagent via npm, reference it from their browser code with `require('superagent')`, and then build their own application bundle via `browserify`, which will use `lib/client.js` as the superagent entrypoint.
121
+ **npm (for browserify)** is handled via the `package.json` `browser` field which allows users to install SuperAgent via npm, reference it from their browser code with `require('superagent')`, and then build their own application bundle via `browserify`, which will use `lib/client.js` as the SuperAgent entrypoint.
124
122
 
125
123
  **bower** is configured via the `bower.json` file. Bower installs files directly from git/github without any transformation.
126
124
 
package/component.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "superagent",
3
3
  "repo": "visionmedia/superagent",
4
- "version": "1.9.0",
4
+ "version": "2.1.0",
5
5
  "description": "elegant & feature rich browser / node HTTP with a fluent API",
6
6
  "keywords": [
7
7
  "http",
@@ -14,8 +14,7 @@
14
14
  ],
15
15
  "main": "lib/client.js",
16
16
  "dependencies": {
17
- "component/emitter": "*",
18
- "component/reduce": "*"
17
+ "component/emitter": "*"
19
18
  },
20
19
  "license": "MIT"
21
20
  }
package/docs/index.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # SuperAgent
3
3
 
4
- Super Agent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node.js!
4
+ SuperAgent is light-weight progressive ajax API crafted for flexibility, readability, and a low learning curve after being frustrated with many of the existing request APIs. It also works with Node.js!
5
5
 
6
6
  request
7
7
  .post('/api/pet')
@@ -46,7 +46,7 @@ ES6 promises are supported. Instead of `.end()` you can call `.then()`:
46
46
 
47
47
  });
48
48
 
49
- __DELETE__, __HEAD__, __POST__, __PUT__ and other __HTTP__ verbs may also be used, simply change the method name:
49
+ __DELETE__, __HEAD__, __PATCH__, __POST__, and __PUT__ requests can also be used, simply change the method name:
50
50
 
51
51
  request
52
52
  .head('/favicon.ico')
@@ -199,7 +199,7 @@ You can also use the `.query()` method for HEAD requests. The following will pro
199
199
 
200
200
  ## Serializing request body
201
201
 
202
- Superagent will automatically serialize JSON and forms. If you want to send the payload in a custom format, you can replace the built-in serialization with `.serialize()` method.
202
+ SuperAgent will automatically serialize JSON and forms. If you want to send the payload in a custom format, you can replace the built-in serialization with `.serialize()` method.
203
203
 
204
204
  ## Setting Accept
205
205
 
@@ -227,7 +227,9 @@ In a similar fashion to the `.type()` method it is also possible to set the Acce
227
227
 
228
228
  ## Parsing response bodies
229
229
 
230
- Super Agent will parse known response-body data for you, currently supporting `application/x-www-form-urlencoded`, `application/json`, and `multipart/form-data`. You can set a custom parser (that takes precedence over built-in parsers) with the `.parse(fn)` method.
230
+ SuperAgent will parse known response-body data for you, currently supporting `application/x-www-form-urlencoded`, `application/json`, and `multipart/form-data`.
231
+
232
+ You can set a custom parser (that takes precedence over built-in parsers) with the `.buffer(true).parse(fn)` method. If response buffering is not enabled (`.buffer(false)`) then the `response` event will be emitted without waiting for the body parser to finish, so `response.body` won't be available.
231
233
 
232
234
  ### JSON / Urlencoded
233
235
 
@@ -313,19 +315,24 @@ In a similar fashion to the `.type()` method it is also possible to set the Acce
313
315
  is set to the `ms` value. __NOTE__ that this is a timeout applied to the request
314
316
  and all subsequent redirects, not per request.
315
317
 
316
- ## Basic authentication
317
-
318
- Basic auth is currently provided by the _node_ client in two forms, first via the URL as "user:pass":
319
-
320
- request.get('http://tobi:learnboost@local').end(callback);
318
+ ## Authentication
321
319
 
322
- As well as via the `.auth()` method:
320
+ In both Node and browsers auth available via the `.auth()` method:
323
321
 
324
322
  request
325
323
  .get('http://local')
326
324
  .auth('tobi', 'learnboost')
327
325
  .end(callback);
328
326
 
327
+
328
+ In the _Node_ client Basic auth can be in the URL as "user:pass":
329
+
330
+ request.get('http://tobi:learnboost@local').end(callback);
331
+
332
+ By default only `Basic` auth is used. In browser you can add `{type:'auto'}` to enable all methods built-in in the browser (Digest, NTLM, etc.):
333
+
334
+ request.auth('digest', 'secret', {type:'auto'})
335
+
329
336
  ## Following redirects
330
337
 
331
338
  By default up to 5 redirects will be followed, however you may specify this with the `res.redirects(n)` method:
@@ -358,7 +365,7 @@ In a similar fashion to the `.type()` method it is also possible to set the Acce
358
365
 
359
366
  ## Multipart requests
360
367
 
361
- Super Agent is also great for _building_ multipart requests for which it provides methods `.attach()` and `.field()`.
368
+ SuperAgent is also great for _building_ multipart requests for which it provides methods `.attach()` and `.field()`.
362
369
 
363
370
  ### Attaching files
364
371
 
@@ -447,17 +454,23 @@ Your callback function will always be passed two arguments: error and response.
447
454
 
448
455
  ## Promise and Generator support
449
456
 
450
- Superagent's request is a "thenable" object that's compatible with JavaScript promises.
457
+ SuperAgent's request is a "thenable" object that's compatible with JavaScript promises and `async`/`await` syntax.
451
458
 
452
- Libraries like [co](https://github.com/tj/co) or a web framework like [koa](https://github.com/koajs/koa) can `yield` on any superagent method:
459
+ Libraries like [co](https://github.com/tj/co) or a web framework like [koa](https://github.com/koajs/koa) can `yield` on any SuperAgent method:
453
460
 
454
461
  var res = yield request
455
462
  .get('http://local')
456
463
  .auth('tobi', 'learnboost')
457
464
 
458
- Note that superagent expects the global `Promise` object to be present. You'll need a polyfill to use promises in Internet Explorer or Node.js 0.10.
465
+ Note that SuperAgent expects the global `Promise` object to be present. You'll need a polyfill to use promises in Internet Explorer or Node.js 0.10.
466
+
467
+
468
+ ## Browser and node versions
469
+
470
+ SuperAgent has two implementations: one for web browsers (using XHR) and one for Node.JS (using core http module). By default Browserify and WebPack will pick the browser version.
459
471
 
472
+ If want to use WebPack to compile code for Node.JS, you *must* specify [node target](webpack.github.io/docs/configuration.html#target) in its configuration.
460
473
 
461
- ## Using browser version in electron
474
+ ### Using browser version in electron
462
475
 
463
- [Electron](http://electron.atom.io/) developers report if you would prefer to use the browser version of superagent instead of the node version, you can `require('superagent/superagent')`. Your requests will now show up in the chrome developer tools network tab. Note this environment is not covered by automated test suite and not officially supported.
476
+ [Electron](http://electron.atom.io/) developers report if you would prefer to use the browser version of SuperAgent instead of the Node version, you can `require('superagent/superagent')`. Your requests will now show up in the Chrome developer tools Network tab. Note this environment is not covered by automated test suite and not officially supported.
package/docs/tail.html CHANGED
@@ -1,9 +1,24 @@
1
1
  </div>
2
2
  <a href="http://github.com/visionmedia/superagent"><img style="position: absolute; top: 0; right: 0; border: 0;" src="https://s3.amazonaws.com/github/ribbons/forkme_right_white_ffffff.png" alt="Fork me on GitHub"></a>
3
- <script src="docs/jquery.js"></script>
4
- <script src="docs/jquery-ui.min.js"></script>
5
- <script src="docs/highlight.js"></script>
6
- <script src="docs/jquery.tocify.min.js"></script>
3
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
4
+ <script>
5
+ $('code').each(function(){
6
+ $(this).html(highlight($(this).text()));
7
+ });
8
+
9
+ function highlight(js) {
10
+ return js
11
+ .replace(/</g, '&lt;')
12
+ .replace(/>/g, '&gt;')
13
+ .replace(/('.*?')/gm, '<span class="string">$1</span>')
14
+ .replace(/(\d+\.\d+)/gm, '<span class="number">$1</span>')
15
+ .replace(/(\d+)/gm, '<span class="number">$1</span>')
16
+ .replace(/\bnew *(\w+)/gm, '<span class="keyword">new</span> <span class="init">$1</span>')
17
+ .replace(/\b(function|new|throw|return|var|if|else)\b/gm, '<span class="keyword">$1</span>')
18
+ }
19
+ </script>
20
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
21
+ <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery.tocify/1.9.0/javascripts/jquery.tocify.min.js"></script>
7
22
  <script>
8
23
  $('#menu').tocify({
9
24
  selectors: 'h2',
package/lib/client.js CHANGED
@@ -1,12 +1,3 @@
1
- /**
2
- * Module dependencies.
3
- */
4
-
5
- var Emitter = require('emitter');
6
- var reduce = require('reduce');
7
- var requestBase = require('./request-base');
8
- var isObject = require('./is-object');
9
-
10
1
  /**
11
2
  * Root reference for iframes.
12
3
  */
@@ -17,9 +8,14 @@ if (typeof window !== 'undefined') { // Browser window
17
8
  } else if (typeof self !== 'undefined') { // Web Worker
18
9
  root = self;
19
10
  } else { // Other environments
11
+ console.warn("Using browser-only version of superagent in non-browser environment");
20
12
  root = this;
21
13
  }
22
14
 
15
+ var Emitter = require('emitter');
16
+ var requestBase = require('./request-base');
17
+ var isObject = require('./is-object');
18
+
23
19
  /**
24
20
  * Noop.
25
21
  */
@@ -47,7 +43,7 @@ request.getXHR = function () {
47
43
  try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {}
48
44
  try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {}
49
45
  }
50
- return false;
46
+ throw Error("Browser-only verison of superagent could not find XHR");
51
47
  };
52
48
 
53
49
  /**
@@ -74,9 +70,7 @@ function serialize(obj) {
74
70
  if (!isObject(obj)) return obj;
75
71
  var pairs = [];
76
72
  for (var key in obj) {
77
- if (null != obj[key]) {
78
- pushEncodedKeyValuePair(pairs, key, obj[key]);
79
- }
73
+ pushEncodedKeyValuePair(pairs, key, obj[key]);
80
74
  }
81
75
  return pairs.join('&');
82
76
  }
@@ -91,18 +85,22 @@ function serialize(obj) {
91
85
  */
92
86
 
93
87
  function pushEncodedKeyValuePair(pairs, key, val) {
94
- if (Array.isArray(val)) {
95
- return val.forEach(function(v) {
96
- pushEncodedKeyValuePair(pairs, key, v);
97
- });
98
- } else if (isObject(val)) {
99
- for(var subkey in val) {
100
- pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
88
+ if (val != null) {
89
+ if (Array.isArray(val)) {
90
+ val.forEach(function(v) {
91
+ pushEncodedKeyValuePair(pairs, key, v);
92
+ });
93
+ } else if (isObject(val)) {
94
+ for(var subkey in val) {
95
+ pushEncodedKeyValuePair(pairs, key + '[' + subkey + ']', val[subkey]);
96
+ }
97
+ } else {
98
+ pairs.push(encodeURIComponent(key)
99
+ + '=' + encodeURIComponent(val));
101
100
  }
102
- return;
101
+ } else if (val === null) {
102
+ pairs.push(encodeURIComponent(key));
103
103
  }
104
- pairs.push(encodeURIComponent(key)
105
- + '=' + encodeURIComponent(val));
106
104
  }
107
105
 
108
106
  /**
@@ -252,10 +250,10 @@ function type(str){
252
250
  */
253
251
 
254
252
  function params(str){
255
- return reduce(str.split(/ *; */), function(obj, str){
256
- var parts = str.split(/ *= */)
257
- , key = parts.shift()
258
- , val = parts.shift();
253
+ return str.split(/ *; */).reduce(function(obj, str){
254
+ var parts = str.split(/ *= */),
255
+ key = parts.shift(),
256
+ val = parts.shift();
259
257
 
260
258
  if (key && val) obj[key] = val;
261
259
  return obj;
@@ -497,23 +495,23 @@ function Request(method, url) {
497
495
 
498
496
  self.emit('response', res);
499
497
 
500
- if (err) {
501
- return self.callback(err, res);
502
- }
503
-
498
+ var new_err;
504
499
  try {
505
- if (res.status >= 200 && res.status < 300) {
506
- return self.callback(err, res);
500
+ if (res.status < 200 || res.status >= 300) {
501
+ new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
502
+ new_err.original = err;
503
+ new_err.response = res;
504
+ new_err.status = res.status;
507
505
  }
506
+ } catch(e) {
507
+ new_err = e; // #985 touching res may cause INVALID_STATE_ERR on old Android
508
+ }
508
509
 
509
- var new_err = new Error(res.statusText || 'Unsuccessful HTTP response');
510
- new_err.original = err;
511
- new_err.response = res;
512
- new_err.status = res.status;
513
-
510
+ // #1000 don't catch errors from the callback to avoid double calling it
511
+ if (new_err) {
514
512
  self.callback(new_err, res);
515
- } catch(e) {
516
- self.callback(e); // #985 touching res may cause INVALID_STATE_ERR on old Android
513
+ } else {
514
+ self.callback(null, res);
517
515
  }
518
516
  });
519
517
  }
@@ -775,24 +773,24 @@ Request.prototype.end = function(fn){
775
773
  };
776
774
 
777
775
  // progress
778
- var handleProgress = function(e){
776
+ var handleProgress = function(direction, e) {
779
777
  if (e.total > 0) {
780
778
  e.percent = e.loaded / e.total * 100;
781
779
  }
782
- e.direction = 'download';
780
+ e.direction = direction;
783
781
  self.emit('progress', e);
784
- };
785
- if (this.hasListeners('progress')) {
786
- xhr.onprogress = handleProgress;
787
782
  }
788
- try {
789
- if (xhr.upload && this.hasListeners('progress')) {
790
- xhr.upload.onprogress = handleProgress;
783
+ if (this.hasListeners('progress')) {
784
+ try {
785
+ xhr.onprogress = handleProgress.bind(null, 'download');
786
+ if (xhr.upload) {
787
+ xhr.upload.onprogress = handleProgress.bind(null, 'upload');
788
+ }
789
+ } catch(e) {
790
+ // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
791
+ // Reported here:
792
+ // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
791
793
  }
792
- } catch(e) {
793
- // Accessing xhr.upload fails in IE from a web worker, so just pretend it doesn't exist.
794
- // Reported here:
795
- // https://connect.microsoft.com/IE/feedback/details/837245/xmlhttprequest-upload-throws-invalid-argument-when-used-from-web-worker-context
796
794
  }
797
795
 
798
796
  // timeout
@@ -855,8 +853,8 @@ request.Request = Request;
855
853
  * GET `url` with optional callback `fn(res)`.
856
854
  *
857
855
  * @param {String} url
858
- * @param {Mixed|Function} data or fn
859
- * @param {Function} fn
856
+ * @param {Mixed|Function} [data] or fn
857
+ * @param {Function} [fn]
860
858
  * @return {Request}
861
859
  * @api public
862
860
  */
@@ -873,8 +871,8 @@ request.get = function(url, data, fn){
873
871
  * HEAD `url` with optional callback `fn(res)`.
874
872
  *
875
873
  * @param {String} url
876
- * @param {Mixed|Function} data or fn
877
- * @param {Function} fn
874
+ * @param {Mixed|Function} [data] or fn
875
+ * @param {Function} [fn]
878
876
  * @return {Request}
879
877
  * @api public
880
878
  */
@@ -891,8 +889,8 @@ request.head = function(url, data, fn){
891
889
  * OPTIONS query to `url` with optional callback `fn(res)`.
892
890
  *
893
891
  * @param {String} url
894
- * @param {Mixed|Function} data or fn
895
- * @param {Function} fn
892
+ * @param {Mixed|Function} [data] or fn
893
+ * @param {Function} [fn]
896
894
  * @return {Request}
897
895
  * @api public
898
896
  */
@@ -909,7 +907,7 @@ request.options = function(url, data, fn){
909
907
  * DELETE `url` with optional callback `fn(res)`.
910
908
  *
911
909
  * @param {String} url
912
- * @param {Function} fn
910
+ * @param {Function} [fn]
913
911
  * @return {Request}
914
912
  * @api public
915
913
  */
@@ -927,8 +925,8 @@ request['delete'] = del;
927
925
  * PATCH `url` with optional `data` and callback `fn(res)`.
928
926
  *
929
927
  * @param {String} url
930
- * @param {Mixed} data
931
- * @param {Function} fn
928
+ * @param {Mixed} [data]
929
+ * @param {Function} [fn]
932
930
  * @return {Request}
933
931
  * @api public
934
932
  */
@@ -945,8 +943,8 @@ request.patch = function(url, data, fn){
945
943
  * POST `url` with optional `data` and callback `fn(res)`.
946
944
  *
947
945
  * @param {String} url
948
- * @param {Mixed} data
949
- * @param {Function} fn
946
+ * @param {Mixed} [data]
947
+ * @param {Function} [fn]
950
948
  * @return {Request}
951
949
  * @api public
952
950
  */
@@ -963,8 +961,8 @@ request.post = function(url, data, fn){
963
961
  * PUT `url` with optional `data` and callback `fn(res)`.
964
962
  *
965
963
  * @param {String} url
966
- * @param {Mixed|Function} data or fn
967
- * @param {Function} fn
964
+ * @param {Mixed|Function} [data] or fn
965
+ * @param {Function} [fn]
968
966
  * @return {Request}
969
967
  * @api public
970
968
  */
package/lib/node/agent.js CHANGED
@@ -6,7 +6,7 @@
6
6
  var CookieJar = require('cookiejar').CookieJar;
7
7
  var CookieAccess = require('cookiejar').CookieAccessInfo;
8
8
  var parse = require('url').parse;
9
- var request = require('./index');
9
+ var request = require('../..');
10
10
  var methods = require('methods');
11
11
 
12
12
  /**
@@ -23,7 +23,11 @@ module.exports = Agent;
23
23
 
24
24
  function Agent(options) {
25
25
  if (!(this instanceof Agent)) return new Agent(options);
26
- if (options) this._ca = options.ca;
26
+ if (options) {
27
+ this._ca = options.ca;
28
+ this._key = options.key;
29
+ this._cert = options.cert;
30
+ }
27
31
  this.jar = new CookieJar;
28
32
  }
29
33
 
@@ -70,6 +74,8 @@ methods.forEach(function(method){
70
74
  Agent.prototype[name] = function(url, fn){
71
75
  var req = request(method, url);
72
76
  req.ca(this._ca);
77
+ req.key(this._key);
78
+ req.cert(this._cert);
73
79
 
74
80
  req.on('response', this._saveCookies.bind(this));
75
81
  req.on('redirect', this._saveCookies.bind(this));