superagent
Advanced tools
Comparing version 0.14.4 to 0.14.5
@@ -5,3 +5,3 @@ { | ||
"description": "awesome http requests", | ||
"version": "0.14.4", | ||
"version": "0.14.5", | ||
"keywords": [ | ||
@@ -8,0 +8,0 @@ "http", |
0.14.5 / 2013-05-23 | ||
================== | ||
* add flag to ensure the callback is __never__ invoked twice | ||
0.14.4 / 2013-05-22 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -5,7 +5,7 @@ /** | ||
var CookieJar = require('cookiejar').CookieJar | ||
, CookieAccess = require('cookiejar').CookieAccessInfo | ||
, parse = require('url').parse | ||
, request = require('./index') | ||
, methods = require('methods'); | ||
var CookieJar = require('cookiejar').CookieJar; | ||
var CookieAccess = require('cookiejar').CookieAccessInfo; | ||
var parse = require('url').parse; | ||
var request = require('./index'); | ||
var methods = require('methods'); | ||
@@ -12,0 +12,0 @@ /** |
@@ -11,16 +11,16 @@ /*! | ||
var Stream = require('stream').Stream | ||
, formidable = require('formidable') | ||
, Response = require('./response') | ||
, parse = require('url').parse | ||
, format = require('url').format | ||
, methods = require('methods') | ||
, utils = require('./utils') | ||
, Part = require('./part') | ||
, mime = require('mime') | ||
, https = require('https') | ||
, http = require('http') | ||
, fs = require('fs') | ||
, qs = require('qs') | ||
, util = require('util'); | ||
var formidable = require('formidable'); | ||
var Response = require('./response'); | ||
var parse = require('url').parse; | ||
var format = require('url').format; | ||
var methods = require('methods'); | ||
var Stream = require('stream'); | ||
var utils = require('./utils'); | ||
var Part = require('./part'); | ||
var mime = require('mime'); | ||
var https = require('https'); | ||
var http = require('http'); | ||
var fs = require('fs'); | ||
var qs = require('qs'); | ||
var util = require('util'); | ||
@@ -508,5 +508,3 @@ /** | ||
Request.prototype.field = function(name, val){ | ||
this.part() | ||
.name(name) | ||
.write(val); | ||
this.part().name(name).write(val); | ||
return this; | ||
@@ -524,7 +522,8 @@ }; | ||
if (this.req) return this.req; | ||
var self = this | ||
, options = {} | ||
, data = this._data | ||
, url = this.url; | ||
var self = this; | ||
var options = {}; | ||
var data = this._data; | ||
var url = this.url; | ||
// default to http:// | ||
@@ -587,2 +586,4 @@ if (0 != url.indexOf('http')) url = 'http://' + url; | ||
this.clearTimeout(); | ||
if (this.called) return; | ||
this.called = true; | ||
if (2 == fn.length) return fn(err, res); | ||
@@ -603,8 +604,8 @@ if (err) return this.emit('error', err); | ||
Request.prototype.end = function(fn){ | ||
var self = this | ||
, data = this._data | ||
, req = this.request() | ||
, buffer = this._buffer | ||
, method = this.method | ||
, timeout = this._timeout; | ||
var self = this; | ||
var data = this._data; | ||
var req = this.request(); | ||
var buffer = this._buffer; | ||
var method = this.method; | ||
var timeout = this._timeout; | ||
@@ -641,9 +642,9 @@ // store callback | ||
req.on('response', function(res){ | ||
var max = self._maxRedirects | ||
, mime = utils.type(res.headers['content-type'] || '') | ||
, type = mime.split('/') | ||
, subtype = type[1] | ||
, type = type[0] | ||
, multipart = 'multipart' == type | ||
, redirect = isRedirect(res.statusCode); | ||
var max = self._maxRedirects; | ||
var mime = utils.type(res.headers['content-type'] || ''); | ||
var type = mime.split('/'); | ||
var subtype = type[1]; | ||
var type = type[0]; | ||
var multipart = 'multipart' == type; | ||
var redirect = isRedirect(res.statusCode); | ||
@@ -752,6 +753,6 @@ // redirect | ||
Request.prototype.attachmentSize = function(fn){ | ||
var files = this.attachments | ||
, pending = files.length | ||
, bytes = 0 | ||
, self = this; | ||
var files = this.attachments; | ||
var pending = files.length; | ||
var bytes = 0; | ||
var self = this; | ||
@@ -773,6 +774,6 @@ files.forEach(function(file){ | ||
Request.prototype.writeAttachments = function(){ | ||
var files = this.attachments | ||
, req = this.request() | ||
, written = 0 | ||
, self = this; | ||
var files = this.attachments; | ||
var req = this.request(); | ||
var written = 0; | ||
var self = this; | ||
@@ -847,6 +848,3 @@ this.attachmentSize(function(total){ | ||
methods.forEach(function(method){ | ||
var name = 'delete' == method | ||
? 'del' | ||
: method; | ||
var name = 'delete' == method ? 'del' : method; | ||
method = method.toUpperCase(); | ||
@@ -853,0 +851,0 @@ request[name] = function(url, fn){ |
@@ -12,7 +12,7 @@ | ||
var utils = require('./utils') | ||
, Stream = require('stream').Stream | ||
, mime = require('mime') | ||
, path = require('path') | ||
, basename = path.basename; | ||
var utils = require('./utils'); | ||
var Stream = require('stream').Stream; | ||
var mime = require('mime'); | ||
var path = require('path'); | ||
var basename = path.basename; | ||
@@ -19,0 +19,0 @@ /** |
@@ -6,4 +6,4 @@ | ||
var utils = require('./utils') | ||
, Stream = require('stream'); | ||
var utils = require('./utils'); | ||
var Stream = require('stream'); | ||
@@ -10,0 +10,0 @@ /** |
@@ -6,5 +6,5 @@ | ||
var Stream = require('stream').Stream | ||
, StringDecoder = require('string_decoder').StringDecoder | ||
, zlib; | ||
var Stream = require('stream'); | ||
var StringDecoder = require('string_decoder').StringDecoder; | ||
var zlib; | ||
@@ -28,5 +28,5 @@ /** | ||
exports.uid = function(len){ | ||
var buf = '' | ||
, chars = 'abcdefghijklmnopqrstuvwxyz123456789' | ||
, nchars = chars.length; | ||
var buf = ''; | ||
var chars = 'abcdefghijklmnopqrstuvwxyz123456789'; | ||
var nchars = chars.length; | ||
while (len--) buf += chars[Math.random() * nchars | 0]; | ||
@@ -33,0 +33,0 @@ return buf; |
{ | ||
"name": "superagent", | ||
"version": "0.14.4", | ||
"version": "0.14.5", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
36
test.js
var express = require('express'); | ||
var app = express(); | ||
app.use(express.cookieParser('something')); | ||
app.use(express.session()); | ||
app.get('/', function(req, res){ | ||
if (!req.session.n) req.session.n = Math.random(); | ||
res.send('hello ' + req.session.n); | ||
}); | ||
app.listen(4000); | ||
var request = require('./'); | ||
var agent = request.agent(); | ||
var n = 3; | ||
function next() { | ||
agent | ||
.get('http://localhost:4000/') | ||
.end(function(res){ | ||
console.log(res.text); | ||
if (n--) process.nextTick(next); | ||
}); | ||
} | ||
next(); | ||
request | ||
.get('http://arstechnica.com/information-technology/2013/05/fios-customer-discovers-the-limits-of-unlimited-data-77-tb-in-month/') | ||
.end(function(err, res){ | ||
console.log(err); | ||
console.log(res.header); | ||
console.log(res.text); | ||
}) |
102774
28
3508