Merge tag '3.17.1'
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 d2d0aff, 4b1b8e4 · Browse files · 5 files·+159 added−20 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+159 added−20 removed
- tests:+76 added−6 removed
- other:+83 added−14 removed
Provenance
- Commit
3dca534- Tree
79dcc06- Author
Douglas Christopher Wilson <doug@somethingdoug.com>- Committer
Douglas Christopher Wilson <doug@somethingdoug.com>- Parent 1
d2d0aff- Parent 2
4b1b8e4
5 files changed+159 added−20 removed
modified:examples/view-constructor/github-view.js+3 added-3 removed
32 unmodified lines3334353637383738394041424343444546474 unmodified lines32 unmodified lines
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 }); res.on('end', function(){4 unmodified linesmodified:lib/request.js+10 added-4 removed
2 unmodified lines3 */4 5 var accepts = require('accepts');6 var deprecate = require('depd')('express');7+var isIP = require('net').isIP;8 var typeis = require('type-is');9 var http = require('http');10 var fresh = require('fresh');11 var parseRange = require('range-parser');320 unmodified lines332 * @api public333 */334 335 defineGetter(req, 'subdomains', function subdomains() {336+ var hostname = this.hostname;337+338+ if (!hostname) return [];339+340 var offset = this.app.get('subdomain offset');336- return (this.hostname || '')337- .split('.')338- .reverse()339- .slice(offset);341+ var subdomains = !isIP(hostname)342+ ? hostname.split('.').reverse()343+ : [hostname];344+345+ return subdomains.slice(offset);346 });347 348 /**349 * Short-hand for `url.parse(req.url).pathname`.111 unmodified linesmodified:test/req.subdomains.js+76 added-6 removed
13 unmodified lines141516171818192021222324252627282930313233343536373839404142434445464748495 unmodified lines555657583359606162636 unmodified lines70717273487475767778798081828384858687888990919293949596975 unmodified lines103104105106651071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391406 unmodified lines147148149150811511521531541557 unmodified lines1631641651669716716816917017117213 unmodified lines
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); }) })
describe('otherwise', function(){ it('should return an empty array', function(done){5 unmodified lines
request(app) .get('/') .set('Host', 'example.com') .expect([], done); .expect(200, [], done); }) })
describe('with no host', function(){6 unmodified lines });
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); }) })
describe('when subdomain offset is set', function(){ describe('when subdomain offset is zero', function(){ it('should return an array with the whole domain', function(done){ var app = express();5 unmodified lines
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); }) })
describe('when present', function(){ it('should return an array', function(done){6 unmodified lines
request(app) .get('/') .set('Host', 'tobi.ferrets.sub.example.com') .expect(["ferrets","tobi"], done); .expect(200, ['ferrets', 'tobi'], done); }) })
describe('otherwise', function(){7 unmodified lines
request(app) .get('/') .set('Host', 'sub.example.com') .expect([], done); .expect(200, [], done); }) }) }) })})modified:History.md+63 added
1+unreleased2+==========3+4+ * Support IP address host in `req.subdomains`5+ * deps: cookie-signature@1.0.56+ * deps: debug@~2.0.07+ * deps: fresh@0.2.48+ * deps: media-typer@0.3.09+ - Throw error when parameter format invalid on parse10+ * deps: range-parser@~1.0.211+ * deps: send@0.9.112+ - Add `lastModified` option13+ - Use `etag` to generate `ETag` header14+ - deps: debug@~2.0.015+ - deps: fresh@0.2.416+ * deps: vary@~1.0.017+ - Accept valid `Vary` header string as `field`18+19 4.8.8 / 2014-09-0420 ==================21 22 * deps: send@0.8.5423 unmodified lines446 - `app.router()` - returns the app Router instance447 - `app.route()` - Proxy to the app's `Router#route()` method to create a new route448 - Router & Route - public API449 450+3.17.1 / 2014-09-08451+===================452+453+ * Fix error in `req.subdomains` on empty host454+455+3.17.0 / 2014-09-08456+===================457+458+ * Support `X-Forwarded-Host` in `req.subdomains`459+ * Support IP address host in `req.subdomains`460+ * deps: connect@2.26.0461+ - deps: body-parser@~1.8.1462+ - deps: compression@~1.1.0463+ - deps: connect-timeout@~1.3.0464+ - deps: cookie-parser@~1.3.3465+ - deps: cookie-signature@1.0.5466+ - deps: csurf@~1.6.1467+ - deps: debug@~2.0.0468+ - deps: errorhandler@~1.2.0469+ - deps: express-session@~1.8.1470+ - deps: finalhandler@0.2.0471+ - deps: fresh@0.2.4472+ - deps: media-typer@0.3.0473+ - deps: method-override@~2.2.0474+ - deps: morgan@~1.3.0475+ - deps: qs@2.2.3476+ - deps: serve-favicon@~2.1.3477+ - deps: serve-index@~1.2.1478+ - deps: serve-static@~1.6.1479+ - deps: type-is@~1.5.1480+ - deps: vhost@~3.0.0481+ * deps: cookie-signature@1.0.5482+ * deps: debug@~2.0.0483+ * deps: fresh@0.2.4484+ * deps: media-typer@0.3.0485+ - Throw error when parameter format invalid on parse486+ * deps: range-parser@~1.0.2487+ * deps: send@0.9.1488+ - Add `lastModified` option489+ - Use `etag` to generate `ETag` header490+ - deps: debug@~2.0.0491+ - deps: fresh@0.2.4492+ * deps: vary@~1.0.0493+ - Accept valid `Vary` header string as `field`494+495 3.16.10 / 2014-09-04496 ====================497 498 * deps: connect@2.25.101706 unmodified linesmodified:package.json+7 added-7 removed
27 unmodified lines28 "homepage": "http://expressjs.com/",29 "dependencies": {30 "accepts": "~1.0.7",31 "buffer-crc32": "0.2.3",32+ "cookie-signature": "1.0.5",32- "debug": "1.0.4",33+ "debug": "~2.0.0",34 "depd": "0.4.4",35 "escape-html": "1.0.1",36 "finalhandler": "0.1.0",37+ "fresh": "0.2.4",36- "media-typer": "0.2.0",38+ "media-typer": "0.3.0",39 "methods": "1.1.0",40 "parseurl": "~1.3.0",41 "path-to-regexp": "0.1.3",42 "proxy-addr": "1.0.1",43 "qs": "2.2.2",42- "range-parser": "1.0.0",43- "send": "0.8.5",44+ "range-parser": "~1.0.2",45+ "send": "0.9.1",46 "serve-static": "~1.5.4",47 "type-is": "~1.3.2",46- "vary": "0.1.0",48+ "vary": "~1.0.0",49 "cookie": "0.1.2",48- "fresh": "0.2.2",49- "cookie-signature": "1.0.4",50 "merge-descriptors": "0.0.2",51 "utils-merge": "1.0.0"52 },53 "devDependencies": {28 unmodified lines