Skip to content

Commit

Permalink
Merge tag '3.17.1'
Browse files Browse the repository at this point in the history
  • Loading branch information
dougwilson committed Sep 9, 2014
2 parents d2d0aff + 4b1b8e4 commit 3dca534
Show file tree
Hide file tree
Showing 5 changed files with 159 additions and 20 deletions.
63 changes: 63 additions & 0 deletions History.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
unreleased
==========

* Support IP address host in `req.subdomains`
* deps: cookie-signature@1.0.5
* deps: debug@~2.0.0
* deps: fresh@0.2.4
* deps: media-typer@0.3.0
- Throw error when parameter format invalid on parse
* deps: range-parser@~1.0.2
* deps: send@0.9.1
- Add `lastModified` option
- Use `etag` to generate `ETag` header
- deps: debug@~2.0.0
- deps: fresh@0.2.4
* deps: vary@~1.0.0
- Accept valid `Vary` header string as `field`

4.8.8 / 2014-09-04
==================

Expand Down Expand Up @@ -429,6 +447,51 @@
- `app.route()` - Proxy to the app's `Router#route()` method to create a new route
- Router & Route - public API

3.17.1 / 2014-09-08
===================

* Fix error in `req.subdomains` on empty host

3.17.0 / 2014-09-08
===================

* Support `X-Forwarded-Host` in `req.subdomains`
* Support IP address host in `req.subdomains`
* deps: connect@2.26.0
- deps: body-parser@~1.8.1
- deps: compression@~1.1.0
- deps: connect-timeout@~1.3.0
- deps: cookie-parser@~1.3.3
- deps: cookie-signature@1.0.5
- deps: csurf@~1.6.1
- deps: debug@~2.0.0
- deps: errorhandler@~1.2.0
- deps: express-session@~1.8.1
- deps: finalhandler@0.2.0
- deps: fresh@0.2.4
- deps: media-typer@0.3.0
- deps: method-override@~2.2.0
- deps: morgan@~1.3.0
- deps: qs@2.2.3
- deps: serve-favicon@~2.1.3
- deps: serve-index@~1.2.1
- deps: serve-static@~1.6.1
- deps: type-is@~1.5.1
- deps: vhost@~3.0.0
* deps: cookie-signature@1.0.5
* deps: debug@~2.0.0
* deps: fresh@0.2.4
* deps: media-typer@0.3.0
- Throw error when parameter format invalid on parse
* deps: range-parser@~1.0.2
* deps: send@0.9.1
- Add `lastModified` option
- Use `etag` to generate `ETag` header
- deps: debug@~2.0.0
- deps: fresh@0.2.4
* deps: vary@~1.0.0
- Accept valid `Vary` header string as `field`

3.16.10 / 2014-09-04
====================

Expand Down
6 changes: 3 additions & 3 deletions examples/view-constructor/github-view.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,13 @@ function GithubView(name, options){
GithubView.prototype.render = function(options, fn){
var self = this;
var opts = {
host: 'rawgithub.com',
port: 80,
host: 'raw.githubusercontent.com',
port: 443,
path: this.path,
method: 'GET'
};

http.request(opts, function(res) {
https.request(opts, function(res) {
var buf = '';
res.setEncoding('utf8');
res.on('data', function(str){ buf += str });
Expand Down
14 changes: 10 additions & 4 deletions lib/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

var accepts = require('accepts');
var deprecate = require('depd')('express');
var isIP = require('net').isIP;
var typeis = require('type-is');
var http = require('http');
var fresh = require('fresh');
Expand Down Expand Up @@ -332,11 +333,16 @@ defineGetter(req, 'ips', function ips() {
*/

defineGetter(req, 'subdomains', function subdomains() {
var hostname = this.hostname;

if (!hostname) return [];

var offset = this.app.get('subdomain offset');
return (this.hostname || '')
.split('.')
.reverse()
.slice(offset);
var subdomains = !isIP(hostname)
? hostname.split('.').reverse()
: [hostname];

return subdomains.slice(offset);
});

/**
Expand Down
14 changes: 7 additions & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -29,24 +29,24 @@
"dependencies": {
"accepts": "~1.0.7",
"buffer-crc32": "0.2.3",
"debug": "1.0.4",
"cookie-signature": "1.0.5",
"debug": "~2.0.0",
"depd": "0.4.4",
"escape-html": "1.0.1",
"finalhandler": "0.1.0",
"media-typer": "0.2.0",
"fresh": "0.2.4",
"media-typer": "0.3.0",
"methods": "1.1.0",
"parseurl": "~1.3.0",
"path-to-regexp": "0.1.3",
"proxy-addr": "1.0.1",
"qs": "2.2.2",
"range-parser": "1.0.0",
"send": "0.8.5",
"range-parser": "~1.0.2",
"send": "0.9.1",
"serve-static": "~1.5.4",
"type-is": "~1.3.2",
"vary": "0.1.0",
"vary": "~1.0.0",
"cookie": "0.1.2",
"fresh": "0.2.2",
"cookie-signature": "1.0.4",
"merge-descriptors": "0.0.2",
"utils-merge": "1.0.0"
},
Expand Down
82 changes: 76 additions & 6 deletions test/req.subdomains.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,33 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'tobi.ferrets.example.com')
.expect(["ferrets","tobi"], done);
.expect(200, ['ferrets', 'tobi'], done);
})

it('should work with IPv4 address', function(done){
var app = express();

app.use(function(req, res){
res.send(req.subdomains);
});

request(app)
.get('/')
.set('Host', '127.0.0.1')
.expect(200, [], done);
})

it('should work with IPv6 address', function(done){
var app = express();

app.use(function(req, res){
res.send(req.subdomains);
});

request(app)
.get('/')
.set('Host', '[::1]')
.expect(200, [], done);
})
})

Expand All @@ -30,7 +56,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'example.com')
.expect([], done);
.expect(200, [], done);
})
})

Expand All @@ -45,7 +71,23 @@ describe('req', function(){

request(app)
.get('/')
.expect([], done);
.expect(200, [], done);
})
})

describe('with trusted X-Forwarded-Host', function () {
it('should return an array', function (done) {
var app = express();

app.set('trust proxy', true);
app.use(function (req, res) {
res.send(req.subdomains);
});

request(app)
.get('/')
.set('X-Forwarded-Host', 'tobi.ferrets.example.com')
.expect(200, ['ferrets', 'tobi'], done);
})
})

Expand All @@ -62,7 +104,35 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'tobi.ferrets.sub.example.com')
.expect(["com","example","sub","ferrets","tobi"], done);
.expect(200, ['com', 'example', 'sub', 'ferrets', 'tobi'], done);
})

it('should return an array with the whole IPv4', function (done) {
var app = express();
app.set('subdomain offset', 0);

app.use(function(req, res){
res.send(req.subdomains);
});

request(app)
.get('/')
.set('Host', '127.0.0.1')
.expect(200, ['127.0.0.1'], done);
})

it('should return an array with the whole IPv6', function (done) {
var app = express();
app.set('subdomain offset', 0);

app.use(function(req, res){
res.send(req.subdomains);
});

request(app)
.get('/')
.set('Host', '[::1]')
.expect(200, ['[::1]'], done);
})
})

Expand All @@ -78,7 +148,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'tobi.ferrets.sub.example.com')
.expect(["ferrets","tobi"], done);
.expect(200, ['ferrets', 'tobi'], done);
})
})

Expand All @@ -94,7 +164,7 @@ describe('req', function(){
request(app)
.get('/')
.set('Host', 'sub.example.com')
.expect([], done);
.expect(200, [], done);
})
})
})
Expand Down

0 comments on commit 3dca534

Please sign in to comment.