(self: HttpServerRequest)
| 1189 | * @since 4.0.0 |
| 1190 | */ |
| 1191 | export 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`. |
no test coverage detected