change res.redirect() to use scheme-relative urls
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 e84db12 · Browse files · 2 files·+9 added−29 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
2 files+9 added−29 removed
- tests:+8 added−28 removed
- other:+1 added−1 removed
Provenance
- Commit
d66f0e5- Tree
04c2fef- Author
TJ Holowaychuk <tj@vision-media.ca>- Committer
TJ Holowaychuk <tj@vision-media.ca>- Parent
e84db12
2 files changed+9 added−29 removed
modified:lib/response.js+1 added-1 removed
529 unmodified lines530 }531 532 // Absolute533 var host = req.get('Host');534- url = req.protocol + '://' + host + url;534+ url = '//' + host + url;535 }536 537 // Support text/{plain,html} by default538 this.format({64 unmodified linesmodified:test/res.redirect.js+8 added-28 removed
2 unmodified lines3 , request = require('./support/http');4 5 describe('res', function(){6 describe('.redirect(url)', function(){7- it('should respect X-Forwarded-Proto when "trust proxy" is enabled', function(done){8- var app = express();9-10- app.enable('trust proxy');11-12- app.use(function(req, res){13- res.redirect('/login');14- });15-16- request(app)17- .get('/')18- .set('Host', 'example.com')19- .set('X-Forwarded-Proto', 'https')20- .end(function(err, res){21- res.statusCode.should.equal(302);22- res.headers.should.have.property('location', 'https://example.com/login');23- done();24- })25- })26-7 it('should default to a 302 redirect', function(done){8 var app = express();9 10 app.use(function(req, res){9 unmodified lines20 })21 })22 23 describe('with leading /', function(){44- it('should construct host-relative urls', function(done){24+ it('should construct scheme-relative urls', function(done){25 var app = express();26 27 app.use(function(req, res){28 res.redirect('/login');2 unmodified lines31 request(app)32 .get('/')33 .set('Host', 'example.com')34 .end(function(err, res){55- res.headers.should.have.property('location', 'http://example.com/login');35+ res.headers.should.have.property('location', '//example.com/login');36 done();37 })38 })39 })9 unmodified lines49 request(app)50 .get('/post/1')51 .set('Host', 'example.com')52 .end(function(err, res){73- res.headers.should.have.property('location', 'http://example.com/post/1/./edit');53+ res.headers.should.have.property('location', '//example.com/post/1/./edit');54 done();55 })56 })57 })9 unmodified lines67 request(app)68 .get('/post/1')69 .set('Host', 'example.com')70 .end(function(err, res){91- res.headers.should.have.property('location', 'http://example.com/post/1/../new');71+ res.headers.should.have.property('location', '//example.com/post/1/../new');72 done();73 })74 })75 })9 unmodified lines85 request(app)86 .get('/')87 .set('Host', 'example.com')88 .end(function(err, res){109- res.headers.should.have.property('location', 'http://example.com/login');89+ res.headers.should.have.property('location', '//example.com/login');90 done();91 })92 })93 })15 unmodified lines109 request(app)110 .get('/blog/admin')111 .set('Host', 'example.com')112 .end(function(err, res){133- res.headers.should.have.property('location', 'http://example.com/blog/admin/login');113+ res.headers.should.have.property('location', '//example.com/blog/admin/login');114 done();115 })116 })117 })12 unmodified lines130 request(app)131 .get('/blog')132 .set('Host', 'example.com')133 .end(function(err, res){154- res.headers.should.have.property('location', 'http://example.com/blog/admin/login');134+ res.headers.should.have.property('location', '//example.com/blog/admin/login');135 done();136 })137 })138 })12 unmodified lines151 request(app)152 .get('/blog')153 .set('Host', 'example.com')154 .end(function(err, res){175- res.headers.should.have.property('location', 'http://example.com/admin/login');155+ res.headers.should.have.property('location', '//example.com/admin/login');156 done();157 })158 })159 })100 unmodified lines