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

Function toURL

packages/effect/src/http/HttpServerRequest.ts:1191–1200  ·  view source on GitHub ↗
(self: HttpServerRequest)

Source from the content-addressed store, hash-verified

1189 * @since 4.0.0
1190 */
1191export const toURL = (self: HttpServerRequest): Option.Option<URL> => {
1192 const host = self.headers.host ?? "localhost"
1193 const protocol = self.protocol ?? (/^https:/i.test(self.originalUrl) ? "https" : "http")
1194 try {
1195 // Prefix paths with `.` so leading `//` cannot replace the host.
1196 return Option.some(new URL(self.url.startsWith("/") ? `.${self.url}` : self.url, `${protocol}://${host}`))
1197 } catch {
1198 return Option.none()
1199 }
1200}
1201
1202/**
1203 * 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