Skip to content
Myr

Merge branch '4.1.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 be997fd, 92d3767 · Browse files · 6 files+83 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+83 added−6 removed

  • tests:+57 added−2 removed
  • other:+26 added−4 removed

6 files+83 added−6 removed

modified:lib/request.js+7 added-1 removed
346 unmodified lines
347 var trustProxy = this.app.get('trust proxy');348 var host = trustProxy && this.get('X-Forwarded-Host');349 host = host || this.get('Host');350 if (!host) return;351 return host.split(':')[0];351 var offset = host[0] === '['352 ? host.indexOf(']') + 1353 : 0;354 var index = host.indexOf(':', offset);355 return ~index356 ? host.substring(0, index)357 : host;358});359360/**361 * Check if the request is fresh, aka
46 unmodified lines
modified:lib/response.js+6 added-2 removed
230 unmodified lines
231232 // content-type233 this.get('Content-Type') || this.set('Content-Type', 'application/json');234235 // fixup callback236 if (Array.isArray(callback)) {237 callback = callback[0];238 }239240 // jsonp236 if (callback) {237 if (Array.isArray(callback)) callback = callback[0];241 if (callback && 'string' === typeof callback) {242 this.set('Content-Type', 'text/javascript');243 var cb = callback.replace(/[^\[\]\w$.]/g, '');244 body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';245 }
539 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');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');
160 unmodified lines
220 })221 })222 })223208 describe('.json(status, object)', function(){224 describe('.jsonp(status, object)', function(){225 it('should respond with json and set the .statusCode', function(done){226 var app = express();227228 app.use(function(req, res){
10 unmodified lines
239 })240 })241 })242227 describe('.json(object, status)', function(){243 describe('.jsonp(object, status)', function(){244 it('should respond with json and set the .statusCode for backwards compat', function(done){245 var app = express();246247 app.use(function(req, res){
32 unmodified lines
modified:History.md+12 added
14.1.2 / 2014-05-082==================34 * fix `req.host` for IPv6 literals5 * fix `res.jsonp` error if callback param is object674.1.1 / 2014-04-278==================910 * fix package.json to reflect supported node version
40 unmodified lines
51 - `app.router()` - returns the app Router instance52 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route53 - Router & Route - public API54553.5.3 / 2014-05-0856==================5758 * fix `req.host` for IPv6 literals59 * fix `res.jsonp` error if callback param is object60613.5.2 / 2014-04-2462==================6364 * update connect to 2.14.5
1273 unmodified lines
modified:package.json+1 added-1 removed