Skip to content

Commit fb178e1

Browse files
author
vhess
committed
use xfwd host to test succesfull usage of proxy
1 parent d24f40f commit fb178e1

File tree

3 files changed

+9
-6
lines changed

3 files changed

+9
-6
lines changed

lib/test/lib/http-proxy-passes-web-incoming.test.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ describe("#createProxyServer.web() using own http server", () => {
602602

603603
it("should proxy requests to multiple servers with different options", () =>
604604
new Promise<void>((done) => {
605-
const proxy = httpProxy.createProxyServer();
605+
const proxy = httpProxy.createProxyServer({xfwd: true});
606606

607607
// proxies to two servers depending on url, rewriting the url as well
608608
// http://127.0.0.1:8080/s1/ -> http://127.0.0.1:8081/
@@ -628,7 +628,7 @@ describe("#createProxyServer.web() using own http server", () => {
628628

629629
const source1 = http.createServer((req, res) => {
630630
expect(req.method).toEqual("GET");
631-
expect(req.headers.host?.split(":")[1]).toEqual(`${port(8080)}`);
631+
expect((req.headers["x-forwarded-host"] as string)?.split(":")[1]).toEqual(`${port(8080)}`);
632632
expect(req.url).toEqual("/test1");
633633
res.end();
634634
});
@@ -638,7 +638,7 @@ describe("#createProxyServer.web() using own http server", () => {
638638
source2.close();
639639
proxyServer.close();
640640
expect(req.method).toEqual("GET");
641-
expect(req.headers.host?.split(":")[1]).toEqual(`${port(8080)}`);
641+
expect((req.headers["x-forwarded-host"] as string)?.split(":")[1]).toEqual(`${port(8080)}`);
642642
expect(req.url).toEqual("/test2");
643643
res.end();
644644
done();

lib/test/lib/http2-proxy.test.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ describe("HTTP2 to HTTP", () => {
2828
const source = http
2929
.createServer((req, res) => {
3030
expect(req.method).toEqual("GET");
31-
expect(req.headers.host?.split(":")[1]).toEqual(`${ports.proxy}`);
31+
expect((req.headers["x-forwarded-host"] as string)?.split(":")[1]).toEqual(`${ports.proxy}`);
3232
res.writeHead(200, { "Content-Type": "text/plain" });
3333
res.end("Hello from " + ports.source);
3434
})
@@ -46,6 +46,7 @@ describe("HTTP2 to HTTP", () => {
4646
),
4747
ciphers: "AES128-GCM-SHA256",
4848
},
49+
xfwd: true,
4950
})
5051
.listen(ports.proxy);
5152

@@ -73,14 +74,15 @@ describe("HTTP2 to HTTP using own server", () => {
7374
const source = http
7475
.createServer((req, res) => {
7576
expect(req.method).toEqual("GET");
76-
expect(req.headers.host?.split(":")[1]).toEqual(`${ports.proxy}`);
77+
expect((req.headers["x-forwarded-host"] as string)?.split(":")[1]).toEqual(`${ports.proxy}`);
7778
res.writeHead(200, { "Content-Type": "text/plain" });
7879
res.end("Hello from " + ports.source);
7980
})
8081
.listen(ports.source);
8182

8283
const proxy = httpProxy.createServer({
8384
agent: new http.Agent({ maxSockets: 2 }),
85+
xfwd: true,
8486
});
8587

8688
const ownServer = http2

lib/test/lib/https-proxy.test.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ describe("HTTPS to HTTP", () => {
3030
const source = http
3131
.createServer((req, res) => {
3232
expect(req.method).toEqual("GET");
33-
expect(req.headers.host?.split(":")[1]).toEqual(`${ports.proxy}`);
33+
expect((req.headers["x-forwarded-host"] as string)?.split(":")[1]).toEqual(`${ports.proxy}`);
3434
res.writeHead(200, { "Content-Type": "text/plain" });
3535
res.end("Hello from " + ports.source);
3636
})
@@ -48,6 +48,7 @@ describe("HTTPS to HTTP", () => {
4848
),
4949
ciphers: "AES128-GCM-SHA256",
5050
},
51+
xfwd: true,
5152
})
5253
.listen(ports.proxy);
5354

0 commit comments

Comments
 (0)