diff --git a/src/index.test.ts b/src/index.test.ts index 7894843..6164c0b 100644 --- a/src/index.test.ts +++ b/src/index.test.ts @@ -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({}); }); diff --git a/src/utils.ts b/src/utils.ts index 608cdc0..6201370 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -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;