Skip to content

Commit 3fc5030

Browse files
authored
Merge pull request #12 from Teneff/auth-with-authorization-header
fixes #11 Basic auth with authorization request header
2 parents 9246a05 + 510b3d5 commit 3fc5030

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

lib/http-proxy/common.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export function setupOutgoing(
8282
}
8383

8484
if (options.auth) {
85+
delete outgoing.headers.authorization;
8586
outgoing.auth = options.auth;
8687
}
8788

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

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -568,6 +568,45 @@ describe("#createProxyServer.web() using own http server", () => {
568568
});
569569
});
570570

571+
describe("with authorization request header", () => {
572+
const headers = {
573+
authorization: `Bearer ${Buffer.from("dummy-oauth-token").toString(
574+
"base64"
575+
)}`,
576+
};
577+
578+
it("should proxy the request with the Authorization header set", (done) => {
579+
const auth = "user:pass";
580+
const proxy = httpProxy.createProxyServer({
581+
target: address(8080),
582+
auth,
583+
});
584+
const proxyServer = http.createServer(proxy.web);
585+
586+
const source = http.createServer((req, res) => {
587+
source.close();
588+
proxyServer.close();
589+
expect(req).toEqual(
590+
expect.objectContaining({
591+
method: "GET",
592+
headers: expect.objectContaining({
593+
authorization: `Basic ${Buffer.from(auth).toString("base64")}`,
594+
}),
595+
})
596+
);
597+
res.end();
598+
done();
599+
});
600+
601+
proxyServer.listen(port(8081));
602+
source.listen(port(8080));
603+
604+
http.request(address(8081), {
605+
headers
606+
}).end();
607+
});
608+
});
609+
571610
describe("#followRedirects", () => {
572611
it("gets some ports", async () => {
573612
for (let n = 8080; n < 8082; n++) {

0 commit comments

Comments
 (0)