Skip to content
This repository was archived by the owner on Aug 5, 2020. It is now read-only.

Commit f04310c

Browse files
Use req.hostname for hostname query in axios client (#1221)
* Use req.hostname for hostname query This will ensure that the value of X-Forwarded-Host is used whenever trust proxy is enabled, falling back to the normal host header when it is disabled.
1 parent 60b8607 commit f04310c

File tree

2 files changed

+7
-3
lines changed

2 files changed

+7
-3
lines changed

packages/gluestick/shared/lib/__tests__/getHttpClient.test.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -139,10 +139,12 @@ describe('lib/getHttpClient', () => {
139139
});
140140

141141
it('should set baseURL with https if req.secure is true', () => {
142+
const host = 'hola.com:332211';
142143
const req = {
144+
hostname: host,
143145
headers: {
144146
cookie: 'name=Lincoln',
145-
host: 'hola.com:332211',
147+
host,
146148
},
147149
secure: true,
148150
};
@@ -153,10 +155,12 @@ describe('lib/getHttpClient', () => {
153155
});
154156

155157
it('should set baseURL with http if req.secure is false', () => {
158+
const host = 'hola.com:332211';
156159
const req = {
160+
hostname: host,
157161
headers: {
158162
cookie: 'name=Lincoln',
159-
host: 'hola.com:332211',
163+
host,
160164
},
161165
secure: false,
162166
};

packages/gluestick/shared/lib/getHttpClient.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export default function getHttpClient(
4747
// If a request object is provided, then we want to merge the custom headers
4848
// with the headers that we sent from the browser in the request.
4949
client = httpClient.create({
50-
baseURL: protocol + req.headers.host,
50+
baseURL: protocol + req.hostname,
5151
headers: {
5252
...headers,
5353
},

0 commit comments

Comments
 (0)