superagent
Advanced tools
Comparing version 0.1.1 to 0.1.2
0.1.2 / 2011-09-24 | ||
================== | ||
* Added markdown documentation | ||
* Added `request(url[, fn])` support to the client | ||
* Added `qs` dependency to package.json | ||
* Added options for `Request#pipe()` | ||
* Added support for `request(url, callback)` | ||
* Added `request(url)` as shortcut for `request.get(url)` | ||
* Added `Request#pipe(stream)` | ||
* Added inherit from `Stream` | ||
* Added multipart support | ||
* Added ssl support (node) | ||
* Removed Content-Length field from client | ||
* Fixed buffering, `setEncoding()` to utf8 [reported by stagas] | ||
* Fixed "end" event when piping | ||
0.1.1 / 2011-08-20 | ||
@@ -3,0 +20,0 @@ ================== |
/*! | ||
* superagent | ||
* Copyright (c) 2010 TJ Holowaychuk <tj@vision-media.ca> | ||
* Copyright (c) 2011 TJ Holowaychuk <tj@vision-media.ca> | ||
* MIT Licensed | ||
@@ -37,14 +37,6 @@ */ | ||
} else { | ||
try { | ||
return new ActiveXObject('Microsoft.XMLHTTP'); | ||
} catch(e) {} | ||
try { | ||
return new ActiveXObject('Msxml2.XMLHTTP.6.0'); | ||
} catch(e) {} | ||
try { | ||
return new ActiveXObject('Msxml2.XMLHTTP.3.0'); | ||
} catch(e) {} | ||
try { | ||
return new ActiveXObject('Msxml2.XMLHTTP'); | ||
} catch(e) {} | ||
try { return new ActiveXObject('Microsoft.XMLHTTP'); } catch(e) {} | ||
try { return new ActiveXObject('Msxml2.XMLHTTP.6.0'); } catch(e) {} | ||
try { return new ActiveXObject('Msxml2.XMLHTTP.3.0'); } catch(e) {} | ||
try { return new ActiveXObject('Msxml2.XMLHTTP'); } catch(e) {} | ||
} | ||
@@ -75,3 +67,3 @@ return false; | ||
function isFunction(obj) { | ||
return obj && obj.call && obj.apply; | ||
return 'function' == typeof obj; | ||
} | ||
@@ -157,2 +149,3 @@ | ||
, urlencoded: 'application/x-www-form-urlencoded' | ||
, 'form-data': 'application/x-www-form-urlencoded' | ||
}; | ||
@@ -495,3 +488,3 @@ | ||
* request.post('/user') | ||
* .type('urlencoded') | ||
* .type('form-data') | ||
* .data('name=tj') | ||
@@ -502,3 +495,3 @@ * .end(callback) | ||
* request.post('/user') | ||
* .type('urlencoded') | ||
* .type('form-data') | ||
* .data({ name: 'tj' }) | ||
@@ -601,7 +594,2 @@ * .end(callback) | ||
if (serialize) data = serialize(data); | ||
// content-length | ||
if (null != data && !this.header['content-length']) { | ||
this.set('Content-Length', data.length); | ||
} | ||
} | ||
@@ -626,6 +614,12 @@ | ||
/** | ||
* Shortcut for `new Request(method, url)`. | ||
* Issue a request: | ||
* | ||
* Examples: | ||
* | ||
* request('GET', '/users').end(callback) | ||
* request('/users').end(callback) | ||
* request('/users', callback) | ||
* | ||
* @param {String} method | ||
* @param {String} url | ||
* @param {String|Function} url or callback | ||
* @return {Request} | ||
@@ -636,2 +630,12 @@ * @api public | ||
function request(method, url) { | ||
// callback | ||
if ('function' == typeof url) { | ||
return new Request('GET', method).end(url); | ||
} | ||
// url first | ||
if (1 == arguments.length) { | ||
return new Request('GET', method); | ||
} | ||
return new Request(method, url); | ||
@@ -638,0 +642,0 @@ } |
{ | ||
"name": "superagent" | ||
, "version": "0.1.1" | ||
, "version": "0.1.2" | ||
, "description": "elegant progressive ajax client" | ||
, "keywords": ["http", "ajax", "request", "agent"] | ||
, "author": "TJ Holowaychuk <tj@vision-media.ca>" | ||
, "dependencies": {} | ||
, "dependencies": { | ||
"qs": "0.3.1" | ||
} | ||
, "devDependencies": { | ||
@@ -9,0 +11,0 @@ "express": "2.4.4" |
# superagent | ||
# SuperAgent | ||
Super-agent is an elegant, small (~1.7kb compressed), progressive client-side HTTP request library. | ||
SuperAgent is an elegant, small (~1.7kb compressed), progressive client-side HTTP request library. View the [docs](http://visionmedia.github.com/superagent/). | ||
![super agent](http://f.cl.ly/items/3d282n3A0h0Z0K2w0q2a/Screenshot.png) | ||
## Links | ||
- API [docs](http://visionmedia.github.com/superagent/) | ||
## About | ||
@@ -97,7 +93,7 @@ | ||
Visit `localhost:3000/test/` in the browser. | ||
Visit `localhost:3000/` in the browser. | ||
## Browser support | ||
Tested in: | ||
Actively tested with: | ||
@@ -108,8 +104,2 @@ - Firefox 5.x | ||
## Future | ||
- finish node port | ||
- more cross-browser support | ||
- jsonp | ||
## License | ||
@@ -116,0 +106,0 @@ |
149
test.js
// TODO: tests | ||
// TODO: nested multipart | ||
// TODO: multipart streaming | ||
// TODO: plugins | ||
// TODO: gunzip (plugin) | ||
// TODO: abort | ||
// TODO: redirect GET only (option?) | ||
// TODO: public redirectsFollowed or w/e | ||
// TODO: global handlers | ||
// TODO: preventDefault() etc for ^ | ||
// TODO: keep-alive | ||
/** | ||
@@ -9,74 +21,81 @@ * Module dependencies. | ||
, app = express.createServer() | ||
, formidable = require('formidable') | ||
, url = require('url') | ||
, fs = require('fs'); | ||
app.get('/', function(req, res){ | ||
console.log('GET /'); | ||
var n = 100; | ||
while (n--) res.write(String(n)); | ||
res.end(); | ||
}); | ||
app.post('/form', function(req, res){ | ||
var form = new formidable.IncomingForm; | ||
form.parse(req, function(err, fields, files){ | ||
if (err) throw err; | ||
console.log(fields); | ||
console.log(files); | ||
res.send('yay'); | ||
}); | ||
}); | ||
app.post('/user', function(req, res){ | ||
req.on('data', function(chunk){ | ||
console.log(chunk.toString()); | ||
}); | ||
req.on('end', function(){ | ||
console.log('<<<end>>>'); | ||
}); | ||
}); | ||
app.listen(3000); | ||
var req = request.post('/user'); | ||
req.on('end', function(){ | ||
console.log('response'); | ||
}); | ||
var stream = fs.createReadStream('package.json'); | ||
stream.pipe(req); | ||
stream.on('end', function(){ | ||
req.end(); | ||
console.log('stream end'); | ||
}); | ||
// var req = request.post('/form'); | ||
// | ||
// app.get('/search', function(req, res){ | ||
// res.redirect('/search/basic'); | ||
// }); | ||
// // var part = req.part() | ||
// // .set('Content-Type', 'application/js'); | ||
// | ||
// app.get('/search/basic', function(req, res){ | ||
// res.redirect('/api/search/basic') | ||
// }); | ||
// fs.createReadStream('test.js') | ||
// .pipe(req); | ||
// | ||
// app.get('/api/search/basic', function(req, res){ | ||
// res.json({ query: req.query }); | ||
// // part.on('end', function(){ | ||
// // console.log('part ended'); | ||
// // }); | ||
// | ||
// req.on('end', function(){ | ||
// console.log('req ended'); | ||
// }); | ||
// request | ||
// .post('/form') | ||
// .type('multipart/mixed; boundary=luna') | ||
// .write('\r\n--luna\r\n') | ||
// .write('Content-Disposition: form-data; name="name"\r\n') | ||
// .write('\r\n') | ||
// .write('manny') | ||
// | ||
// app.listen(3000); | ||
// request.post('/video') | ||
// .type('mixed/related') | ||
// .part() | ||
// .set('Content-Type', 'application/xml') | ||
// .data('<foobar></foobar>') | ||
// .part() | ||
// .set('Content-Type', 'video/webm') | ||
// .set('Content-Length', 123) | ||
// .data(fs.createReadStream('package.json')) // TODO: write several serially | ||
// .end(function(err){ | ||
// if (err) throw err; | ||
// | ||
// }); | ||
// request.post('http://local/user') | ||
// .set('X-API-Key', 'foobar') | ||
// .pipe(fs.createReadStream('package.json')) | ||
// .write('\r\n') | ||
// .write('--luna\r\n') | ||
// .write('Content-Disposition: form-data; name="age"\r\n') | ||
// .write('\r\n') | ||
// .write('1') | ||
// | ||
// .write('\r\n--luna--') | ||
// .end(function(err, res){ | ||
// if (err) throw err; | ||
// console.log(res); | ||
// // if (err) throw err; | ||
// console.log(res.status); | ||
// // console.log(res.text); | ||
// }); | ||
// request.post('http://local/user') | ||
// .set('X-API-Key', 'foobar') | ||
// .write('foo') | ||
// .write('bar') | ||
// .write('baz') | ||
// .end(function(err, res){ | ||
// if (err) throw err; | ||
// console.log(res); | ||
// }); | ||
request.post('http://local/user') | ||
.set('X-API-Key', 'keyboard cat') | ||
.data({ name: 'tj' }) | ||
.data({ age: 24 }) | ||
.end(function(err, res){ | ||
if (err) throw err; | ||
console.log(res); | ||
}); | ||
// request.get('http://local/search') | ||
// .data({ query: 'Tobi' }) | ||
// .data({ limit: '1..5' }) | ||
// .redirects(1) | ||
// .end(function(err, res){ | ||
// if (err) throw err; | ||
// console.log(res.text); | ||
// console.log(res.status); | ||
// console.log(res.redirect); | ||
// console.log(res.ok); | ||
// console.log(res.header); | ||
// console.log(res.body); | ||
// process.exit(); | ||
// }).on('redirect', function(res){ | ||
// console.log('redirect to: %s', res.headers.location); | ||
// });; |
@@ -12,2 +12,6 @@ | ||
app.get('/', function(req, res){ | ||
res.redirect('/test/'); | ||
}); | ||
app.get('/error', function(req, res){ | ||
@@ -14,0 +18,0 @@ res.status(500).send('fail'); |
@@ -374,1 +374,21 @@ | ||
test('request(method, url)', function(next){ | ||
request('GET', '/foo').end(function(res){ | ||
assert('bar' == res.body.foo); | ||
next(); | ||
}); | ||
}); | ||
test('request(url)', function(next){ | ||
request('/foo').end(function(res){ | ||
assert('bar' == res.body.foo); | ||
next(); | ||
}); | ||
}); | ||
test('request(url, fn)', function(next){ | ||
request('/foo', function(res){ | ||
assert('bar' == res.body.foo); | ||
next(); | ||
}); | ||
}); |
Network access
Supply chain riskThis module accesses the network.
Found 1 instance in 1 package
322083
23
9823
1
126
2