Skip to content
Myr

Added X-Forwarded-Proto support to `res.redirect()`. Closes #927

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent e49c482 · Browse files · 3 files+21 added−2 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

3 files+21 added−2 removed

  • tests:+18 added−0 removed
  • other:+3 added−2 removed

3 files+21 added−2 removed

modified:lib/request.js+1 added-1 removed
327 unmodified lines
328 * @api public329 */330331req.__defineGetter__('secure', function(){332 return req.connection.encrypted;332 return this.connection.encrypted;333});334335/**336 * Short-hand for `require('url').parse(req.url).pathname`.
45 unmodified lines
modified:lib/response.js+2 added-1 removed
481 unmodified lines
482 }483484 // Absolute485 var host = req.header('Host')486 , tls = false // TODO: req.secure;486 , proto = req.header('X-Forwarded-Proto')487 , tls = 'https' == proto || req.secure;488489 url = 'http' + (tls ? 's' : '') + '://' + host + url;490 }491
85 unmodified lines
modified:test/res.redirect.js+18 added
2 unmodified lines
3 , request = require('./support/http');45describe('res', function(){6 describe('.redirect(url)', function(){7 it('should respect X-Forwarded-Proto', function(done){8 var app = express();910 app.use(function(req, res){11 res.redirect('/login');12 });1314 request(app)15 .get('/')16 .set('Host', 'example.com')17 .set('X-Forwarded-Proto', 'https')18 .end(function(res){19 res.statusCode.should.equal(302);20 res.headers.should.have.property('location', 'https://example.com/login');21 done();22 })23 })2425 it('should default to a 302 redirect', function(done){26 var app = express();2728 app.use(function(req, res){
226 unmodified lines