Merge branch '3.5.x' into 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 61f2929, dc31ea3 · Browse files · 5 files·+82 added−5 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
5 files+82 added−5 removed
- tests:+57 added−2 removed
- other:+25 added−3 removed
Provenance
- Commit
2901bd6- Tree
f391661- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
61f2929- Parent 2
dc31ea3
5 files changed+82 added−5 removed
modified:lib/request.js+7 added-1 removed
346 unmodified lines347 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 });359 360 /**361 * Check if the request is fresh, aka46 unmodified linesmodified:lib/response.js+6 added-2 removed
230 unmodified lines231 232 // content-type233 this.set('Content-Type', 'application/json');234 235+ // fixup callback236+ if (Array.isArray(callback)) {237+ callback = callback[0];238+ }239+240 // 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 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');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');160 unmodified lines220 })221 })222 })223 208- 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();227 228 app.use(function(req, res){10 unmodified lines239 })240 })241 })242 227- 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();246 247 app.use(function(req, res){14 unmodified linesmodified:History.md+12 added
1+4.1.x2+=====3+4+ * fix `req.host` for IPv6 literals5+ * fix `res.jsonp` error if callback param is object6+7 4.1.1 / 2014-04-278 ==================9 10 * fix package.json to reflect supported node version40 unmodified lines51 - `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 API54 55+3.5.3 / 2014-05-0856+==================57+58+ * fix `req.host` for IPv6 literals59+ * fix `res.jsonp` error if callback param is object60+61 3.5.2 / 2014-04-2462 ==================63 64 * update connect to 2.14.51273 unmodified lines