Skip to content
Source
Sign inSign up
Open History to see the last commit

requestUrl.ts

14 lines604 Bytes

1import * as Option from "effect/Option";
2import { HttpServerRequest } from "effect/http";
3​
4/**
5 * `HttpServerRequest.toURL` that honors `X-Forwarded-Proto: https`. Effect 4.1
6 * stopped reading it, but TLS-terminating proxies in front of the server
7 * (Tailscale Serve, tunnels) rely on it for OAuth, DPoP and pairing URLs.
8 */
9export const requestUrl = (request: HttpServerRequest.HttpServerRequest): Option.Option<URL> =>
10 HttpServerRequest.toURL(
11 request.headers["x-forwarded-proto"] === "https" && request.protocol !== "https"
12 ? request.modify({ protocol: "https" })
13 : request,
14 );