| 238 | * @category conversions |
| 239 | */ |
| 240 | export const toWebEither = (self: HttpServerRequest, options?: { |
| 241 | readonly signal?: AbortSignal | undefined |
| 242 | readonly runtime?: Runtime.Runtime<never> | undefined |
| 243 | }): Either.Either<Request, Error.RequestError> => { |
| 244 | if (self.source instanceof Request) { |
| 245 | return Either.right(self.source) |
| 246 | } |
| 247 | const ourl = toURL(self) |
| 248 | if (Option.isNone(ourl)) { |
| 249 | return Either.left( |
| 250 | new Error.RequestError({ |
| 251 | request: self, |
| 252 | reason: "Decode", |
| 253 | description: "Invalid URL" |
| 254 | }) |
| 255 | ) |
| 256 | } |
| 257 | const requestInit: RequestInit = { |
| 258 | method: self.method, |
| 259 | headers: self.headers, |
| 260 | signal: options?.signal |
| 261 | } |
| 262 | if (hasBody(self.method)) { |
| 263 | requestInit.body = Stream.toReadableStreamRuntime(self.stream, options?.runtime ?? Runtime.defaultRuntime) |
| 264 | ;(requestInit as any).duplex = "half" |
| 265 | } |
| 266 | return Either.right(new Request(ourl.value, requestInit)) |
| 267 | } |
| 268 | |
| 269 | /** |
| 270 | * @since 1.0.0 |