MCPcopy Create free account
hub / github.com/Effect-TS/effect / toURL

Function toURL

packages/effect/src/unstable/http/HttpServerRequest.ts:1025–1033  ·  view source on GitHub ↗
(self: HttpServerRequest)

Source from the content-addressed store, hash-verified

1023 * @since 4.0.0
1024 */
1025export const toURL = (self: HttpServerRequest): Option.Option<URL> => {
1026 const host = self.headers.host ?? "localhost"
1027 const protocol = self.headers["x-forwarded-proto"] === "https" ? "https" : "http"
1028 try {
1029 return Option.some(new URL(self.url, `${protocol}://${host}`))
1030 } catch {
1031 return Option.none()
1032 }
1033}
1034
1035/**
1036 * Converts an `HttpServerRequest` safely to a Web `Request` as a `Result`.

Callers 2

toClientRequestFunction · 0.85
toWebResultFunction · 0.85

Calls 1

someMethod · 0.80

Tested by

no test coverage detected