Skip to content
Myr

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

6 files+77 added−6 removed

modified:lib/request.js+7 added-1 removed
474 unmodified lines
475 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});487488/**489 * Check if the request is fresh, aka
46 unmodified lines
modified:lib/response.js+6 added-2 removed
235 unmodified lines
236 // content-type237 this.charset = this.charset || 'utf-8';238 this.set('Content-Type', 'application/json');239240 // fixup callback241 if (Array.isArray(callback)) {242 callback = callback[0];243 }244245 // 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 lines
modified:test/req.host.js+39 added
modified:test/res.jsonp.js+18 added-2 removed
35 unmodified lines
36 done();37 })38 })3940 it('should ignore object callback parameter with jsonp', function(done){41 var app = express();4243 app.use(function(req, res){44 res.jsonp({ count: 1 });45 });4647 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 })5556 it('should allow renaming callback', function(done){57 var app = express();5859 app.set('jsonp callback name', 'clb');
167 unmodified lines
227 })228 })229 })230215 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();234235 app.use(function(req, res){
10 unmodified lines
246 })247 })248 })249234 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();253254 app.use(function(req, res){
14 unmodified lines
modified:History.md+6 added
17 unmodified lines
18 * update debug to 0.8.019 * add `enable()` method20 * change from stderr to stdout21223.5.3 / 2014-05-0823==================2425 * fix `req.host` for IPv6 literals26 * fix `res.jsonp` error if callback param is object27283.5.2 / 2014-04-2429==================3031 * update connect to 2.14.5
1273 unmodified lines
modified:package.json+1 added-1 removed