From ee38e703cc325a4a8528f5d2be58b65284a5e02f Mon Sep 17 00:00:00 2001 From: Blaine Bublitz Date: Thu, 8 Feb 2024 12:37:50 -0700 Subject: [PATCH] update protocol --- arcjet-next/index.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/arcjet-next/index.ts b/arcjet-next/index.ts index f2348b7e0..558fb0007 100644 --- a/arcjet-next/index.ts +++ b/arcjet-next/index.ts @@ -106,7 +106,7 @@ export function createNextRemoteClient( export interface ArcjetNextRequest { headers?: Record | Headers; - socket?: Partial<{ remoteAddress: string }>; + socket?: Partial<{ remoteAddress: string; encrypted: boolean }>; info?: Partial<{ remoteAddress: string }>; @@ -219,7 +219,7 @@ export default function arcjetNext( const host = headers.get("host") ?? ""; let path = ""; let query = ""; - let protocol = ""; + let protocol = ""; // TODO(#36): nextUrl has formatting logic when you `toString` but // we don't account for that here if (typeof request.nextUrl !== "undefined") { @@ -231,6 +231,11 @@ export default function arcjetNext( protocol = request.nextUrl.protocol } } else { + if (typeof request.socket?.encrypted !== "undefined") { + protocol = request.socket.encrypted ? "https:" : "http:" + } else { + protocol = "http:"; + } // Do some very simple validation, but also try/catch around URL parsing if ( typeof request.url !== "undefined" && @@ -238,7 +243,7 @@ export default function arcjetNext( host !== "" ) { try { - const url = new URL(request.url, `http://${host}`); + const url = new URL(request.url, `${protocol}//${host}`); path = url.pathname; query = url.search; protocol = url.protocol;