superagent 3.4.3 → 3.4.4
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/History.md +7 -0
- package/lib/client.js +10 -3
- package/lib/node/index.js +21 -18
- package/package.json +1 -2
- package/superagent.js +11 -4
package/History.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
# 3.4.3 (2017-02-14)
|
|
2
|
+
|
|
3
|
+
* Fixed being able to define own parsers when their mime type starts with `text/` (Damien Clark)
|
|
4
|
+
* `withCredentials(false)` (Andy Woods)
|
|
5
|
+
* Use `formData.on` instead of `.once` (Kornel Lesiński)
|
|
6
|
+
* Ignore `attach("file",null)` (Kornel Lesiński)
|
|
7
|
+
|
|
1
8
|
# 3.4.1 (2017-01-29)
|
|
2
9
|
|
|
3
10
|
* Allow `retry()` and `retry(0)` (Alexander Pope)
|
package/lib/client.js
CHANGED
|
@@ -12,7 +12,7 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
12
12
|
root = this;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
var Emitter = require('emitter');
|
|
15
|
+
var Emitter = require('component-emitter');
|
|
16
16
|
var RequestBase = require('./request-base');
|
|
17
17
|
var isObject = require('./is-object');
|
|
18
18
|
var isFunction = require('./is-function');
|
|
@@ -501,13 +501,16 @@ Request.prototype.accept = function(type){
|
|
|
501
501
|
* Set Authorization field value with `user` and `pass`.
|
|
502
502
|
*
|
|
503
503
|
* @param {String} user
|
|
504
|
-
* @param {String} pass
|
|
505
|
-
* @param {Object} options with 'type' property 'auto' or '
|
|
504
|
+
* @param {String} [pass] optional in case of using 'bearer' as type
|
|
505
|
+
* @param {Object} options with 'type' property 'auto', 'basic' or 'bearer' (default 'basic')
|
|
506
506
|
* @return {Request} for chaining
|
|
507
507
|
* @api public
|
|
508
508
|
*/
|
|
509
509
|
|
|
510
510
|
Request.prototype.auth = function(user, pass, options){
|
|
511
|
+
if (typeof pass === 'object' && pass !== null) { // pass is optional and can substitute for options
|
|
512
|
+
options = pass;
|
|
513
|
+
}
|
|
511
514
|
if (!options) {
|
|
512
515
|
options = {
|
|
513
516
|
type: 'function' === typeof btoa ? 'basic' : 'auto',
|
|
@@ -523,6 +526,10 @@ Request.prototype.auth = function(user, pass, options){
|
|
|
523
526
|
this.username = user;
|
|
524
527
|
this.password = pass;
|
|
525
528
|
break;
|
|
529
|
+
|
|
530
|
+
case 'bearer': // usage would be .auth(accessToken, { type: 'bearer' })
|
|
531
|
+
this.set('Authorization', 'Bearer ' + user);
|
|
532
|
+
break;
|
|
526
533
|
}
|
|
527
534
|
return this;
|
|
528
535
|
};
|
package/lib/node/index.js
CHANGED
|
@@ -468,18 +468,30 @@ Request.prototype._redirect = function(res){
|
|
|
468
468
|
* .auth('tobi', 'learnboost')
|
|
469
469
|
* .auth('tobi:learnboost')
|
|
470
470
|
* .auth('tobi')
|
|
471
|
+
* .auth(accessToken, { type: 'bearer' })
|
|
471
472
|
*
|
|
472
473
|
* @param {String} user
|
|
473
|
-
* @param {String} pass
|
|
474
|
+
* @param {String} [pass]
|
|
475
|
+
* @param {Object} [options] options with authorization type 'basic' or 'bearer' ('basic' is default)
|
|
474
476
|
* @return {Request} for chaining
|
|
475
477
|
* @api public
|
|
476
478
|
*/
|
|
477
479
|
|
|
478
|
-
Request.prototype.auth = function(user, pass){
|
|
480
|
+
Request.prototype.auth = function(user, pass, options){
|
|
479
481
|
if (1 === arguments.length) pass = '';
|
|
480
|
-
if (
|
|
481
|
-
|
|
482
|
-
|
|
482
|
+
if (2 === arguments.length && typeof pass === 'object') options = pass;
|
|
483
|
+
if (!options) {
|
|
484
|
+
options = { type: 'basic' };
|
|
485
|
+
}
|
|
486
|
+
switch (options.type) {
|
|
487
|
+
case 'bearer':
|
|
488
|
+
return this.set('Authorization', 'Bearer ' + user);
|
|
489
|
+
|
|
490
|
+
default: // 'basic'
|
|
491
|
+
if (!~user.indexOf(':')) user = user + ':';
|
|
492
|
+
var str = new Buffer(user + pass).toString('base64');
|
|
493
|
+
return this.set('Authorization', 'Basic ' + str);
|
|
494
|
+
}
|
|
483
495
|
};
|
|
484
496
|
|
|
485
497
|
/**
|
|
@@ -822,7 +834,7 @@ Request.prototype._end = function() {
|
|
|
822
834
|
var form = new formidable.IncomingForm();
|
|
823
835
|
parser = form.parse.bind(form);
|
|
824
836
|
buffer = true;
|
|
825
|
-
} else if (
|
|
837
|
+
} else if (isImageOrVideo(mime)) {
|
|
826
838
|
parser = exports.parse.image;
|
|
827
839
|
buffer = true; // For backwards-compatibility buffering default is ad-hoc MIME-dependent
|
|
828
840
|
} else if (exports.parse[mime]) {
|
|
@@ -1008,19 +1020,10 @@ function isText(mime) {
|
|
|
1008
1020
|
|| 'x-www-form-urlencoded' == subtype;
|
|
1009
1021
|
}
|
|
1010
1022
|
|
|
1011
|
-
|
|
1012
|
-
|
|
1013
|
-
*
|
|
1014
|
-
* @param {String} mime
|
|
1015
|
-
* @return {Boolean}
|
|
1016
|
-
* @api public
|
|
1017
|
-
*/
|
|
1018
|
-
|
|
1019
|
-
function isImage(mime) {
|
|
1020
|
-
var parts = mime.split('/');
|
|
1021
|
-
var type = parts[0];
|
|
1023
|
+
function isImageOrVideo(mime) {
|
|
1024
|
+
var type = mime.split('/')[0];
|
|
1022
1025
|
|
|
1023
|
-
return 'image' == type;
|
|
1026
|
+
return 'image' == type || 'video' == type;
|
|
1024
1027
|
}
|
|
1025
1028
|
|
|
1026
1029
|
/**
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "superagent",
|
|
3
|
-
"version": "3.4.
|
|
3
|
+
"version": "3.4.4",
|
|
4
4
|
"description": "elegant & feature rich browser / node HTTP with a fluent API",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"prepublish": "make all",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
},
|
|
53
53
|
"browser": {
|
|
54
54
|
"./lib/node/index.js": "./lib/client.js",
|
|
55
|
-
"emitter": "component-emitter",
|
|
56
55
|
"./test/support/server.js": "./test/support/blank.js"
|
|
57
56
|
},
|
|
58
57
|
"component": {
|
package/superagent.js
CHANGED
|
@@ -1023,7 +1023,7 @@ if (typeof window !== 'undefined') { // Browser window
|
|
|
1023
1023
|
root = this;
|
|
1024
1024
|
}
|
|
1025
1025
|
|
|
1026
|
-
var Emitter = require('emitter');
|
|
1026
|
+
var Emitter = require('component-emitter');
|
|
1027
1027
|
var RequestBase = require('./request-base');
|
|
1028
1028
|
var isObject = require('./is-object');
|
|
1029
1029
|
var isFunction = require('./is-function');
|
|
@@ -1512,13 +1512,16 @@ Request.prototype.accept = function(type){
|
|
|
1512
1512
|
* Set Authorization field value with `user` and `pass`.
|
|
1513
1513
|
*
|
|
1514
1514
|
* @param {String} user
|
|
1515
|
-
* @param {String} pass
|
|
1516
|
-
* @param {Object} options with 'type' property 'auto' or '
|
|
1515
|
+
* @param {String} [pass] optional in case of using 'bearer' as type
|
|
1516
|
+
* @param {Object} options with 'type' property 'auto', 'basic' or 'bearer' (default 'basic')
|
|
1517
1517
|
* @return {Request} for chaining
|
|
1518
1518
|
* @api public
|
|
1519
1519
|
*/
|
|
1520
1520
|
|
|
1521
1521
|
Request.prototype.auth = function(user, pass, options){
|
|
1522
|
+
if (typeof pass === 'object' && pass !== null) { // pass is optional and can substitute for options
|
|
1523
|
+
options = pass;
|
|
1524
|
+
}
|
|
1522
1525
|
if (!options) {
|
|
1523
1526
|
options = {
|
|
1524
1527
|
type: 'function' === typeof btoa ? 'basic' : 'auto',
|
|
@@ -1534,6 +1537,10 @@ Request.prototype.auth = function(user, pass, options){
|
|
|
1534
1537
|
this.username = user;
|
|
1535
1538
|
this.password = pass;
|
|
1536
1539
|
break;
|
|
1540
|
+
|
|
1541
|
+
case 'bearer': // usage would be .auth(accessToken, { type: 'bearer' })
|
|
1542
|
+
this.set('Authorization', 'Bearer ' + user);
|
|
1543
|
+
break;
|
|
1537
1544
|
}
|
|
1538
1545
|
return this;
|
|
1539
1546
|
};
|
|
@@ -1934,5 +1941,5 @@ request.put = function(url, data, fn){
|
|
|
1934
1941
|
return req;
|
|
1935
1942
|
};
|
|
1936
1943
|
|
|
1937
|
-
},{"./is-function":1,"./is-object":2,"./request-base":3,"./response-base":4,"./should-retry":5,"emitter":7}]},{},[8])(8)
|
|
1944
|
+
},{"./is-function":1,"./is-object":2,"./request-base":3,"./response-base":4,"./should-retry":5,"component-emitter":7}]},{},[8])(8)
|
|
1938
1945
|
});
|