Skip to content

Commit

Permalink
Make sure no exceptions are thrown if headers is undefined
Browse files Browse the repository at this point in the history
  • Loading branch information
firecow committed Apr 1, 2024
1 parent a5ceba4 commit 7ab20c8
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion src/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ test("Expand request (query params)", () => {
});

test("Expand request (no x-forwarded-proto or host header)", () => {
const info = {req: {url: "/", headers: {}}};
const info = {req: {url: "/"}};
Utils.expandRequest(info);
expect(info).toStrictEqual({});
});
Expand Down
4 changes: 2 additions & 2 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ export class Utils {
const req: any = info["request"] || info["req"];
if (!req) return;

const protocol = req.headers["x-forwarded-proto"] ?? "https";
if (req.headers["host"]) {
if (req.headers) {
const protocol = (req.protocol ?? req.headers["x-forwarded-proto"] ?? "https").replace(":", "");
const url = new URL(req.url, `${protocol}://${req.headers.host}`);
info["url.path"] = url.pathname;
info["url.full"] = url.href;
Expand Down

0 comments on commit 7ab20c8

Please sign in to comment.