mirror of
https://github.com/zebrajr/express.git
synced 2025-12-06 12:19:51 +01:00
Merge branch '4.1.x'
This commit is contained in:
commit
0bbbc84959
12
History.md
12
History.md
|
|
@ -1,3 +1,9 @@
|
||||||
|
4.1.2 / 2014-05-08
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix `req.host` for IPv6 literals
|
||||||
|
* fix `res.jsonp` error if callback param is object
|
||||||
|
|
||||||
4.1.1 / 2014-04-27
|
4.1.1 / 2014-04-27
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
|
@ -46,6 +52,12 @@
|
||||||
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
|
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
|
||||||
- Router & Route - public API
|
- Router & Route - public API
|
||||||
|
|
||||||
|
3.5.3 / 2014-05-08
|
||||||
|
==================
|
||||||
|
|
||||||
|
* fix `req.host` for IPv6 literals
|
||||||
|
* fix `res.jsonp` error if callback param is object
|
||||||
|
|
||||||
3.5.2 / 2014-04-24
|
3.5.2 / 2014-04-24
|
||||||
==================
|
==================
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -348,7 +348,13 @@ req.__defineGetter__('host', function(){
|
||||||
var host = trustProxy && this.get('X-Forwarded-Host');
|
var host = trustProxy && this.get('X-Forwarded-Host');
|
||||||
host = host || this.get('Host');
|
host = host || this.get('Host');
|
||||||
if (!host) return;
|
if (!host) return;
|
||||||
return host.split(':')[0];
|
var offset = host[0] === '['
|
||||||
|
? host.indexOf(']') + 1
|
||||||
|
: 0;
|
||||||
|
var index = host.indexOf(':', offset);
|
||||||
|
return ~index
|
||||||
|
? host.substring(0, index)
|
||||||
|
: host;
|
||||||
});
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -232,9 +232,13 @@ res.jsonp = function(obj){
|
||||||
// content-type
|
// content-type
|
||||||
this.get('Content-Type') || this.set('Content-Type', 'application/json');
|
this.get('Content-Type') || this.set('Content-Type', 'application/json');
|
||||||
|
|
||||||
|
// fixup callback
|
||||||
|
if (Array.isArray(callback)) {
|
||||||
|
callback = callback[0];
|
||||||
|
}
|
||||||
|
|
||||||
// jsonp
|
// jsonp
|
||||||
if (callback) {
|
if (callback && 'string' === typeof callback) {
|
||||||
if (Array.isArray(callback)) callback = callback[0];
|
|
||||||
this.set('Content-Type', 'text/javascript');
|
this.set('Content-Type', 'text/javascript');
|
||||||
var cb = callback.replace(/[^\[\]\w$.]/g, '');
|
var cb = callback.replace(/[^\[\]\w$.]/g, '');
|
||||||
body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';
|
body = 'typeof ' + cb + ' === \'function\' && ' + cb + '(' + body + ');';
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "express",
|
"name": "express",
|
||||||
"description": "Sinatra inspired web development framework",
|
"description": "Sinatra inspired web development framework",
|
||||||
"version": "4.1.1",
|
"version": "4.1.2",
|
||||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||||
"contributors": [
|
"contributors": [
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -18,6 +18,19 @@ describe('req', function(){
|
||||||
.expect('example.com', done);
|
.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){
|
it('should return undefined otherwise', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
|
|
@ -30,5 +43,31 @@ describe('req', function(){
|
||||||
.post('/')
|
.post('/')
|
||||||
.expect('undefined', done);
|
.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);
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -37,6 +37,22 @@ describe('res', function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('should ignore object callback parameter with jsonp', function(done){
|
||||||
|
var app = express();
|
||||||
|
|
||||||
|
app.use(function(req, res){
|
||||||
|
res.jsonp({ count: 1 });
|
||||||
|
});
|
||||||
|
|
||||||
|
request(app)
|
||||||
|
.get('/?callback[a]=something')
|
||||||
|
.end(function(err, res){
|
||||||
|
res.headers.should.have.property('content-type', 'application/json');
|
||||||
|
res.text.should.equal('{"count":1}');
|
||||||
|
done();
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
it('should allow renaming callback', function(done){
|
it('should allow renaming callback', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
|
|
@ -205,7 +221,7 @@ describe('res', function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('.json(status, object)', function(){
|
describe('.jsonp(status, object)', function(){
|
||||||
it('should respond with json and set the .statusCode', function(done){
|
it('should respond with json and set the .statusCode', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
|
|
@ -224,7 +240,7 @@ describe('res', function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('.json(object, status)', function(){
|
describe('.jsonp(object, status)', function(){
|
||||||
it('should respond with json and set the .statusCode for backwards compat', function(done){
|
it('should respond with json and set the .statusCode for backwards compat', function(done){
|
||||||
var app = express();
|
var app = express();
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user