superagent
Advanced tools
Comparing version 0.11.0 to 0.12.0
0.12.0 / 2013-01-04 | ||
================== | ||
* add header persistence on redirects | ||
0.11.0 / 2013-01-02 | ||
@@ -3,0 +8,0 @@ ================== |
@@ -454,2 +454,3 @@ /*! | ||
// location | ||
if (!~url.indexOf('://')) { | ||
@@ -462,6 +463,13 @@ if (0 != url.indexOf('//')) { | ||
// strip Content-* related fields | ||
// in case of POST etc | ||
var header = utils.cleanHeader(this.req._headers); | ||
delete this.req; | ||
// force GET | ||
this.method = 'HEAD' == this.method | ||
? this.method | ||
? 'HEAD' | ||
: 'GET'; | ||
// redirect | ||
this._data = null; | ||
@@ -471,2 +479,3 @@ this.url = url; | ||
this.emit('redirect', res); | ||
this.set(header); | ||
this.end(this._callback); | ||
@@ -473,0 +482,0 @@ return this; |
@@ -132,2 +132,18 @@ | ||
}; | ||
}; | ||
}; | ||
/** | ||
* Strip content related fields from `header`. | ||
* | ||
* @param {Object} header | ||
* @return {Object} header | ||
* @api private | ||
*/ | ||
exports.cleanHeader = function(header){ | ||
delete header['content-type']; | ||
delete header['content-length']; | ||
delete header['transfer-encoding']; | ||
delete header['cookie']; | ||
return header; | ||
}; |
{ | ||
"name": "superagent", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"description": "elegant & feature rich browser / node HTTP with a fluent API", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
35
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(); | ||
request | ||
.get('http://component.io/components/:action/:query') | ||
.params({ action: 'search', query: 'ui' }) | ||
.end(function(res){ | ||
console.log(res.body); | ||
}) | ||
var n = 3; | ||
function next() { | ||
agent | ||
.get('http://localhost:4000/') | ||
.end(function(res){ | ||
console.log(res.text); | ||
if (n--) process.nextTick(next); | ||
}); | ||
} | ||
next(); |
93136
3188