Skip to content

Commit

Permalink
update protocol
Browse files Browse the repository at this point in the history
  • Loading branch information
blaine-arcjet committed Feb 8, 2024
1 parent 43fdf71 commit ee38e70
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions arcjet-next/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export function createNextRemoteClient(
export interface ArcjetNextRequest {
headers?: Record<string, string | string[] | undefined> | Headers;

socket?: Partial<{ remoteAddress: string }>;
socket?: Partial<{ remoteAddress: string; encrypted: boolean }>;

info?: Partial<{ remoteAddress: string }>;

Expand Down Expand Up @@ -219,7 +219,7 @@ export default function arcjetNext<const Rules extends (Primitive | Product)[]>(
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") {
Expand All @@ -231,14 +231,19 @@ export default function arcjetNext<const Rules extends (Primitive | Product)[]>(
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" &&
request.url !== "" &&
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;
Expand Down

0 comments on commit ee38e70

Please sign in to comment.