Skip to content

Commit 62c9984

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

File tree

2 files changed

+5
-4
lines changed

2 files changed

+5
-4
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/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)