Skip to content

Commit 6f46e05

Browse files
committed
Use x-forwarded-proto when constructing the url
1 parent 3f93616 commit 6f46e05

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

lib/process-request.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = (req, options = {}) => {
1616
return {
1717
method: req.method,
1818
url: url.format({
19-
protocol: req.protocol,
19+
protocol: req.headers['x-forwarded-proto'] || req.protocol,
2020
host: req.headers['x-forwarded-host'] || req.get('host'),
2121
pathname: `${req.baseUrl}${req.path}`,
2222
query: req.query,

test/process-request.test.js

+7
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,13 @@ describe('processRequest()', () => {
6363
// This regex is for supertest's random port numbers
6464
.expect(({ body }) => assert(body.url.match(/http:\/\/127.0.0.1:\d+\/path\?a=b/))));
6565

66+
it('#url protocol x-forwarded-proto', () =>
67+
request(createApp())
68+
.post('/')
69+
.set('x-forwarded-proto', 'https')
70+
// This regex is for supertest's random port numbers
71+
.expect(({ body }) => assert(body.url.match(/^https/))));
72+
6673
it('#url-basepath', () =>
6774
request(createApp())
6875
.post('/test-base-path/a')

0 commit comments

Comments
 (0)