Skip to content

Commit 2a14bc7

Browse files
RubenVerborghdmitrizagidulin
authored andcommitted
Set Host header on proxied requests.
1 parent 89b6133 commit 2a14bc7

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/handlers/auth-proxy.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ const proxy = require('http-proxy-middleware')
66
const debug = require('../debug')
77

88
const PROXY_SETTINGS = {
9-
logLevel: 'silent'
9+
logLevel: 'silent',
10+
changeOrigin: true
1011
}
1112

1213
// Registers Auth Proxy handlers for each target

test/unit/auth-proxy.js

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const express = require('express')
44
const request = require('supertest')
55
const { expect } = require('chai')
66

7+
const HOST = 'solid.org'
78
const USER = 'https://ruben.verborgh.org/profile/#me'
89

910
describe('Auth Proxy', () => {
@@ -33,6 +34,7 @@ describe('Auth Proxy', () => {
3334
let response
3435
before(() => {
3536
return request(app).get('/server/a')
37+
.set('Host', HOST)
3638
.then(res => { response = res })
3739
})
3840

@@ -47,6 +49,11 @@ describe('Auth Proxy', () => {
4749
expect(headers).to.have.property('user', USER)
4850
})
4951

52+
it('sets the Host header on the proxy request', () => {
53+
const { headers } = response.body
54+
expect(headers).to.have.property('host', 'server-a.org')
55+
})
56+
5057
it('returns status code 200', () => {
5158
expect(response).to.have.property('statusCode', 200)
5259
})
@@ -56,6 +63,7 @@ describe('Auth Proxy', () => {
5663
let response
5764
before(() => {
5865
return request(app).get('/server/a/my/path?query=string')
66+
.set('Host', HOST)
5967
.then(res => { response = res })
6068
})
6169

@@ -70,6 +78,11 @@ describe('Auth Proxy', () => {
7078
expect(headers).to.have.property('user', USER)
7179
})
7280

81+
it('sets the Host header on the proxy request', () => {
82+
const { headers } = response.body
83+
expect(headers).to.have.property('host', 'server-a.org')
84+
})
85+
7386
it('returns status code 200', () => {
7487
expect(response).to.have.property('statusCode', 200)
7588
})
@@ -79,6 +92,7 @@ describe('Auth Proxy', () => {
7992
let response
8093
before(() => {
8194
return request(app).get('/server/b')
95+
.set('Host', HOST)
8296
.then(res => { response = res })
8397
})
8498

@@ -93,6 +107,11 @@ describe('Auth Proxy', () => {
93107
expect(headers).to.have.property('user', USER)
94108
})
95109

110+
it('sets the Host header on the proxy request', () => {
111+
const { headers } = response.body
112+
expect(headers).to.have.property('host', 'server-b.org')
113+
})
114+
96115
it('returns status code 200', () => {
97116
expect(response).to.have.property('statusCode', 200)
98117
})
@@ -102,6 +121,7 @@ describe('Auth Proxy', () => {
102121
let response
103122
before(() => {
104123
return request(app).get('/server/b/my/path?query=string')
124+
.set('Host', HOST)
105125
.then(res => { response = res })
106126
})
107127

@@ -116,6 +136,11 @@ describe('Auth Proxy', () => {
116136
expect(headers).to.have.property('user', USER)
117137
})
118138

139+
it('sets the Host header on the proxy request', () => {
140+
const { headers } = response.body
141+
expect(headers).to.have.property('host', 'server-b.org')
142+
})
143+
119144
it('returns status code 200', () => {
120145
expect(response).to.have.property('statusCode', 200)
121146
})
@@ -126,6 +151,7 @@ describe('Auth Proxy', () => {
126151
before(() => {
127152
loggedIn = false
128153
return request(app).get('/server/a')
154+
.set('Host', HOST)
129155
.then(res => { response = res })
130156
})
131157
after(() => {
@@ -143,6 +169,11 @@ describe('Auth Proxy', () => {
143169
expect(headers).to.not.have.property('user')
144170
})
145171

172+
it('sets the Host header on the proxy request', () => {
173+
const { headers } = response.body
174+
expect(headers).to.have.property('host', 'server-a.org')
175+
})
176+
146177
it('returns status code 200', () => {
147178
expect(response).to.have.property('statusCode', 200)
148179
})

0 commit comments

Comments
 (0)