MCPcopy
hub / github.com/Effect-TS/effect / toWebEither

Function toWebEither

packages/platform/src/HttpServerRequest.ts:240–267  ·  view source on GitHub ↗
(self: HttpServerRequest, options?: {
  readonly signal?: AbortSignal | undefined
  readonly runtime?: Runtime.Runtime<never> | undefined
})

Source from the content-addressed store, hash-verified

238 * @category conversions
239 */
240export 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

Callers 1

toWebFunction · 0.85

Calls 2

toURLFunction · 0.85
hasBodyFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…