Skip to content

Commit

Permalink
Added support for requires_path_in_header
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinugu committed Oct 14, 2023
1 parent 313f976 commit 273c71d
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/mapper.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ var updateFromJson = function (path, map) {
host: keyToSession[key]["host"],
port: parseInt(keyToSession[key]["port"]),
requires_path_in_url: info?.requires_path_in_url,
requires_path_in_header: info?.requires_path_in_header,
},
};
}
Expand Down Expand Up @@ -66,6 +67,7 @@ var updateFromSqlite = function (path, map) {
key_type: row["key_type"],
token: row["token"],
requires_path_in_url: info?.requires_path_in_url,
requires_path_in_header: info?.requires_path_in_header,
};
},
finish,
Expand Down
9 changes: 9 additions & 0 deletions lib/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,15 @@ DynamicProxy.prototype.targetForRequest = function (request) {
key = path_split[1];
token = path_split[2];

const target_inject_header = this.sessionMap[key]?.requires_path_in_header;
if (target_inject_header) {
request.headers[target_inject_header] = [
this.proxyPathPrefix,
key,
token,
].join("/");
}

if (!this.sessionMap[key]?.requires_path_in_url) {
const target_url = "/" + path_split.slice(3).join("/");
request.url = target_url;
Expand Down
40 changes: 40 additions & 0 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,46 @@ describe("DynamicProxy", function () {
});
});

describe("map based path forwarding to top-level path with entry point path in header", function () {
it(
'should respect session map with requires_path_in_header="X-My-Header", strip entry point path from ' +
'url and instead provide it in header "X-My-Header"',
async function () {
const sessionMap = {
coolkey: {
token: "cooltoken",
target: {
host: "localhost",
port: TEST_PORT,
},
requires_path_in_header: "X-My-Header",
},
};
const proxy = new DynamicProxy({
port: 5103,
verbose: true,
sessionMap: sessionMap,
proxyPathPrefix: "/interactivetool/ep",
});
proxy.listen();
const headers = {
host: "usegalaxy.org",
};

proxy.proxy.on("proxyReq", function (proxyReq) {
proxyReq
.getHeader("X-My-Header")
.should.equal("/interactivetool/ep/coolkey/cooltoken");
});

const path =
"/interactivetool/ep/coolkey/cooltoken/test_data/extradir/README.md";
await verifyProxyOnPort(5103, headers, path);
proxy.close();
},
);
});

describe("double proxying", function () {
it("should proxy across two servers", async function () {
const sessionMap = {
Expand Down

0 comments on commit 273c71d

Please sign in to comment.