Merge branch '3.5.x' into 3.x
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Douglas Christopher Wilson · committed by Douglas Christopher Wilson · parents 4b646c2, dc31ea3 · Browse files · 6 files·+77 added−6 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
6 files+77 added−6 removed
- tests:+57 added−2 removed
- other:+20 added−4 removed
Provenance
- Commit
66b38b5- Tree
4c67682- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
4b646c2- Parent 2
dc31ea3
6 files changed+77 added−6 removed
modified:lib/request.js+7 added-1 removed
474 unmodified lines475 var trustProxy = this.app.get('trust proxy');476 var host = trustProxy && this.get('X-Forwarded-Host');477 host = host || this.get('Host');478 if (!host) return;479- return host.split(':')[0];479+ var offset = host[0] === '['480+ ? host.indexOf(']') + 1481+ : 0;482+ var index = host.indexOf(':', offset);483+ return ~index484+ ? host.substring(0, index)485+ : host;486 });487 488 /**489 * Check if the request is fresh, aka46 unmodified linesmodified:lib/response.js+6 added-2 removed
235 unmodified lines236 // content-type237 this.charset = this.charset || 'utf-8';238 this.set('Content-Type', 'application/json');239 240+ // fixup callback241+ if (Array.isArray(callback)) {242+ callback = callback[0];243+ }244+245 // jsonp241- if (callback) {242- if (Array.isArray(callback)) callback = callback[0];246+ if (callback && 'string' === typeof callback) {247 this.set('Content-Type', 'text/javascript');248 var cb = callback.replace(/[^\[\]\w$.]/g, '');249 body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';250 }553 unmodified linesmodified:test/req.host.js+39 added
16 unmodified lines1718192021222324252627282930313233343536374 unmodified lines424344454647484950515253545556575859606162636465666768697071727316 unmodified lines .set('Host', 'example.com') .expect('example.com', done); })
it('should strip port number', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', 'example.com:3000') .expect('example.com', done); })
it('should return undefined otherwise', function(done){ var app = express();
app.use(function(req, res){4 unmodified lines request(app) .post('/') .expect('undefined', done); })
it('should work with IPv6 Host', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', '[::1]') .expect('[::1]', done); })
it('should work with IPv6 Host and port', function(done){ var app = express();
app.use(function(req, res){ res.end(req.host); });
request(app) .post('/') .set('Host', '[::1]:3000') .expect('[::1]', done); }) })})modified:test/res.jsonp.js+18 added-2 removed
35 unmodified lines36 done();37 })38 })39 40+ it('should ignore object callback parameter with jsonp', function(done){41+ var app = express();42+43+ app.use(function(req, res){44+ res.jsonp({ count: 1 });45+ });46+47+ request(app)48+ .get('/?callback[a]=something')49+ .end(function(err, res){50+ res.headers.should.have.property('content-type', 'application/json; charset=utf-8');51+ res.text.should.equal('{"count":1}');52+ done();53+ })54+ })55+56 it('should allow renaming callback', function(done){57 var app = express();58 59 app.set('jsonp callback name', 'clb');167 unmodified lines227 })228 })229 })230 215- describe('.json(status, object)', function(){231+ describe('.jsonp(status, object)', function(){232 it('should respond with json and set the .statusCode', function(done){233 var app = express();234 235 app.use(function(req, res){10 unmodified lines246 })247 })248 })249 234- describe('.json(object, status)', function(){250+ describe('.jsonp(object, status)', function(){251 it('should respond with json and set the .statusCode for backwards compat', function(done){252 var app = express();253 254 app.use(function(req, res){14 unmodified linesmodified:History.md+6 added
17 unmodified lines18 * update debug to 0.8.019 * add `enable()` method20 * change from stderr to stdout21 22+3.5.3 / 2014-05-0823+==================24+25+ * fix `req.host` for IPv6 literals26+ * fix `res.jsonp` error if callback param is object27+28 3.5.2 / 2014-04-2429 ==================30 31 * update connect to 2.14.51273 unmodified linesmodified:package.json+1 added-1 removed
12344567877 unmodified lines{ "name": "express", "description": "Sinatra inspired web development framework", "version": "3.5.2", "version": "3.5.3", "author": "TJ Holowaychuk <tj@vision-media.ca>", "contributors": [ { "name": "TJ Holowaychuk",77 unmodified lines