superagent 0.15.3 → 0.15.7

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 CHANGED
@@ -1,4 +1,21 @@
1
1
 
2
+ 0.15.7 / 2013-10-19
3
+ ==================
4
+
5
+ * pin should.js to 1.3.0 due to breaking change in 2.0.x
6
+ * fix browserify regression
7
+
8
+ 0.15.5 / 2013-10-09
9
+ ==================
10
+
11
+ * add browser field to support browserify
12
+ * fix .field() value number support
13
+
14
+ 0.15.4 / 2013-07-09
15
+ ==================
16
+
17
+ * node: add a Request#agent() function to set the http Agent to use
18
+
2
19
  0.15.3 / 2013-07-05
3
20
  ==================
4
21
 
package/Readme.md CHANGED
@@ -82,11 +82,11 @@ request.post('/api/pet', cat, function(error, res){
82
82
 
83
83
  $ make test-server
84
84
 
85
- Visit `localhost:3000/` in the browser.
85
+ Visit `localhost:4000/` in the browser.
86
86
 
87
87
  ## Browser build
88
88
 
89
- The browser build of superagent is located in the `./build` directory.
89
+ The browser build of superagent is located in ./superagent.js
90
90
 
91
91
  ## Examples:
92
92
 
package/component.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "superagent",
3
3
  "repo": "visionmedia/superagent",
4
4
  "description": "awesome http requests",
5
- "version": "0.15.3",
5
+ "version": "0.15.4",
6
6
  "keywords": [
7
7
  "http",
8
8
  "ajax",
package/lib/client.js CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  /**
3
2
  * Module dependencies.
4
3
  */
@@ -453,11 +452,10 @@ function Request(method, url) {
453
452
  }
454
453
 
455
454
  /**
456
- * Inherit from `Emitter.prototype`.
455
+ * Mixin `Emitter`.
457
456
  */
458
457
 
459
- Request.prototype = new Emitter;
460
- Request.prototype.constructor = Request;
458
+ Emitter(Request.prototype);
461
459
 
462
460
  /**
463
461
  * Set timeout to `ms`.
package/lib/node/index.js CHANGED
@@ -116,6 +116,7 @@ exports.parse = require('./parsers');
116
116
  function Request(method, url) {
117
117
  var self = this;
118
118
  if ('string' != typeof url) url = format(url);
119
+ this._agent = false;
119
120
  this.method = method;
120
121
  this.url = url;
121
122
  this.header = {};
@@ -184,6 +185,20 @@ Request.prototype.part = function(){
184
185
  return new Part(this);
185
186
  };
186
187
 
188
+ /**
189
+ * Gets/sets the `Agent` to use for this HTTP request. The default (if this
190
+ * function is not called) is to opt out of connection pooling (`agent: false`).
191
+ *
192
+ * @param {http.Agent} agent
193
+ * @return {http.Agent}
194
+ * @api public
195
+ */
196
+
197
+ Request.prototype.agent = function(agent){
198
+ if (agent) this._agent = agent;
199
+ return this._agent;
200
+ };
201
+
187
202
  /**
188
203
  * Set header `field` to `val`, or multiple fields with one object.
189
204
  *
@@ -531,7 +546,7 @@ Request.prototype.auth = function(user, pass){
531
546
  */
532
547
 
533
548
  Request.prototype.field = function(name, val){
534
- this.part().name(name).write(val);
549
+ this.part().name(name).write(String(val));
535
550
  return this;
536
551
  };
537
552
 
@@ -559,7 +574,7 @@ Request.prototype.request = function(){
559
574
  options.port = url.port;
560
575
  options.path = url.pathname;
561
576
  options.host = url.hostname;
562
- options.agent = false;
577
+ options.agent = this._agent;
563
578
 
564
579
  // initiate request
565
580
  var mod = exports.protocols[url.protocol];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "superagent",
3
- "version": "0.15.3",
3
+ "version": "0.15.7",
4
4
  "description": "elegant & feature rich browser / node HTTP with a fluent API",
5
5
  "keywords": [
6
6
  "http",
@@ -23,20 +23,26 @@
23
23
  "emitter-component": "1.0.0",
24
24
  "methods": "0.0.1",
25
25
  "cookiejar": "1.3.0",
26
- "debug": "~0.7.2"
26
+ "debug": "~0.7.2",
27
+ "reduce-component": "1.0.1"
27
28
  },
28
29
  "devDependencies": {
29
30
  "express": "3.3.1",
30
31
  "better-assert": "~0.1.0",
31
- "should": "*",
32
+ "should": "1.3.0",
32
33
  "mocha": "*"
33
34
  },
35
+ "browser": {
36
+ "./lib/node/index.js": "./lib/client.js",
37
+ "emitter": "emitter-component",
38
+ "reduce": "reduce-component"
39
+ },
34
40
  "component": {
35
41
  "scripts": {
36
42
  "superagent": "lib/client.js"
37
43
  }
38
44
  },
39
- "main": "lib/node",
45
+ "main": "./lib/node/index.js",
40
46
  "engines": {
41
47
  "node": "*"
42
48
  }
@@ -1,16 +0,0 @@
1
- {
2
- "name": "reduce",
3
- "repo": "redventures/reduce",
4
- "description": "Array reduce component",
5
- "version": "0.0.1",
6
- "keywords": [
7
- "array",
8
- "reduce"
9
- ],
10
- "dependencies": {},
11
- "development": {},
12
- "license": "Apache, Version 2.0",
13
- "scripts": [
14
- "index.js"
15
- ]
16
- }
@@ -1,24 +0,0 @@
1
-
2
- /**
3
- * Reduce `arr` with `fn`.
4
- *
5
- * @param {Array} arr
6
- * @param {Function} fn
7
- * @param {Mixed} initial
8
- *
9
- * TODO: combatible error handling?
10
- */
11
-
12
- module.exports = function(arr, fn, initial){
13
- var idx = 0;
14
- var len = arr.length;
15
- var curr = arguments.length == 3
16
- ? initial
17
- : arr[idx++];
18
-
19
- while (idx < len) {
20
- curr = fn.call(null, curr, arr[idx], ++idx, arr);
21
- }
22
-
23
- return curr;
24
- };
@@ -1,17 +0,0 @@
1
- {
2
- "name": "emitter",
3
- "description": "Event emitter",
4
- "keywords": [
5
- "emitter",
6
- "events"
7
- ],
8
- "dependencies": {
9
- "component/indexof": "*"
10
- },
11
- "version": "1.0.0",
12
- "scripts": [
13
- "index.js"
14
- ],
15
- "license": "MIT",
16
- "repo": "https://raw.github.com/component/emitter"
17
- }
@@ -1,162 +0,0 @@
1
-
2
- /**
3
- * Module dependencies.
4
- */
5
-
6
- var index = require('indexof');
7
-
8
- /**
9
- * Expose `Emitter`.
10
- */
11
-
12
- module.exports = Emitter;
13
-
14
- /**
15
- * Initialize a new `Emitter`.
16
- *
17
- * @api public
18
- */
19
-
20
- function Emitter(obj) {
21
- if (obj) return mixin(obj);
22
- };
23
-
24
- /**
25
- * Mixin the emitter properties.
26
- *
27
- * @param {Object} obj
28
- * @return {Object}
29
- * @api private
30
- */
31
-
32
- function mixin(obj) {
33
- for (var key in Emitter.prototype) {
34
- obj[key] = Emitter.prototype[key];
35
- }
36
- return obj;
37
- }
38
-
39
- /**
40
- * Listen on the given `event` with `fn`.
41
- *
42
- * @param {String} event
43
- * @param {Function} fn
44
- * @return {Emitter}
45
- * @api public
46
- */
47
-
48
- Emitter.prototype.on = function(event, fn){
49
- this._callbacks = this._callbacks || {};
50
- (this._callbacks[event] = this._callbacks[event] || [])
51
- .push(fn);
52
- return this;
53
- };
54
-
55
- /**
56
- * Adds an `event` listener that will be invoked a single
57
- * time then automatically removed.
58
- *
59
- * @param {String} event
60
- * @param {Function} fn
61
- * @return {Emitter}
62
- * @api public
63
- */
64
-
65
- Emitter.prototype.once = function(event, fn){
66
- var self = this;
67
- this._callbacks = this._callbacks || {};
68
-
69
- function on() {
70
- self.off(event, on);
71
- fn.apply(this, arguments);
72
- }
73
-
74
- fn._off = on;
75
- this.on(event, on);
76
- return this;
77
- };
78
-
79
- /**
80
- * Remove the given callback for `event` or all
81
- * registered callbacks.
82
- *
83
- * @param {String} event
84
- * @param {Function} fn
85
- * @return {Emitter}
86
- * @api public
87
- */
88
-
89
- Emitter.prototype.off =
90
- Emitter.prototype.removeListener =
91
- Emitter.prototype.removeAllListeners = function(event, fn){
92
- this._callbacks = this._callbacks || {};
93
-
94
- // all
95
- if (0 == arguments.length) {
96
- this._callbacks = {};
97
- return this;
98
- }
99
-
100
- // specific event
101
- var callbacks = this._callbacks[event];
102
- if (!callbacks) return this;
103
-
104
- // remove all handlers
105
- if (1 == arguments.length) {
106
- delete this._callbacks[event];
107
- return this;
108
- }
109
-
110
- // remove specific handler
111
- var i = index(callbacks, fn._off || fn);
112
- if (~i) callbacks.splice(i, 1);
113
- return this;
114
- };
115
-
116
- /**
117
- * Emit `event` with the given args.
118
- *
119
- * @param {String} event
120
- * @param {Mixed} ...
121
- * @return {Emitter}
122
- */
123
-
124
- Emitter.prototype.emit = function(event){
125
- this._callbacks = this._callbacks || {};
126
- var args = [].slice.call(arguments, 1)
127
- , callbacks = this._callbacks[event];
128
-
129
- if (callbacks) {
130
- callbacks = callbacks.slice(0);
131
- for (var i = 0, len = callbacks.length; i < len; ++i) {
132
- callbacks[i].apply(this, args);
133
- }
134
- }
135
-
136
- return this;
137
- };
138
-
139
- /**
140
- * Return array of callbacks for `event`.
141
- *
142
- * @param {String} event
143
- * @return {Array}
144
- * @api public
145
- */
146
-
147
- Emitter.prototype.listeners = function(event){
148
- this._callbacks = this._callbacks || {};
149
- return this._callbacks[event] || [];
150
- };
151
-
152
- /**
153
- * Check if this emitter has `event` handlers.
154
- *
155
- * @param {String} event
156
- * @return {Boolean}
157
- * @api public
158
- */
159
-
160
- Emitter.prototype.hasListeners = function(event){
161
- return !! this.listeners(event).length;
162
- };
@@ -1,15 +0,0 @@
1
- {
2
- "name": "indexof",
3
- "description": "Microsoft sucks",
4
- "version": "0.0.1",
5
- "keywords": [
6
- "index",
7
- "array",
8
- "indexOf"
9
- ],
10
- "dependencies": {},
11
- "scripts": [
12
- "index.js"
13
- ],
14
- "repo": "https://raw.github.com/component/indexof"
15
- }
@@ -1,10 +0,0 @@
1
-
2
- var indexOf = [].indexOf;
3
-
4
- module.exports = function(arr, obj){
5
- if (indexOf) return arr.indexOf(obj);
6
- for (var i = 0; i < arr.length; ++i) {
7
- if (arr[i] === obj) return i;
8
- }
9
- return -1;
10
- };
package/test.js DELETED
@@ -1,80 +0,0 @@
1
-
2
- var http = require('http');
3
- var formidable = require('formidable');
4
- var express = require('express');
5
- var request = require('./');
6
-
7
- // var app = express();
8
-
9
- // app.get('/', function(req, res){
10
- // res.set('Content-Type', 'multipart/form-data; boundary=awesome');
11
- // res.write('\r\n');
12
- // res.write('--awesome\r\n');
13
- // res.write('Content-Disposition: attachment; name="image"; filename="something.png"\r\n');
14
- // res.write('Content-Type: image/png\r\n');
15
- // res.write('\r\n');
16
- // res.write('some data');
17
- // res.write('\r\n--awesome\r\n');
18
- // res.write('Content-Disposition: form-data; name="name"\r\n');
19
- // res.write('Content-Type: text/plain\r\n');
20
- // res.write('\r\n');
21
- // res.write('tobi');
22
- // res.write('\r\n--awesome--');
23
- // res.end();
24
- // });
25
-
26
- // app.listen(4000)
27
-
28
- // http.createServer(function(req, res){
29
- // res.setHeader('Content-Type', 'multipart/form-data; boundary=awesome');
30
- // res.write('\r\n');
31
- // res.write('--awesome\r\n');
32
- // res.write('Content-Disposition: attachment; name="image"; filename="something.png"\r\n');
33
- // res.write('Content-Type: image/png\r\n');
34
- // res.write('\r\n');
35
- // res.write('some data');
36
- // res.write('\r\n--awesome\r\n');
37
- // res.write('Content-Disposition: form-data; name="name"\r\n');
38
- // res.write('Content-Type: text/plain\r\n');
39
- // res.write('\r\n');
40
- // res.write('tobi');
41
- // res.write('\r\n--awesome--');
42
- // res.end();
43
- // }).listen(4000);
44
-
45
- // // request
46
- // // .get('http://localhost:4000')
47
- // // .end(function(res){
48
- // // console.log(res);
49
- // // })
50
-
51
- // var url = require('url');
52
- // var opts = url.parse('http://localhost:4000');
53
- // opts.agent = false;
54
-
55
- // http
56
- // .get(opts)
57
- // .on('response', function(res){
58
- // console.log(res.headers);
59
- // var form = new formidable.IncomingForm;
60
-
61
- // form.parse(res, function(err, fields, files){
62
- // if (err) throw err;
63
- // console.log(fields);
64
- // console.log(files);
65
- // });
66
- // })
67
-
68
- var url = 'https://raw.github.com/visionmedia/commander.c/master/src/commander.c';
69
-
70
- request
71
- .get(url)
72
- .pipe(process.stdout)
73
- // .buffer(false)
74
- // .end(function(err, res){
75
- // if (err) throw err;
76
- // console.log(res.header);
77
- // res.on('data', function(chunk){
78
- // console.log(chunk.toString());
79
- // });
80
- // });