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

Function scopeTransferToStream

packages/effect/src/http/HttpEffect.ts:313–335  ·  view source on GitHub ↗
(
  response: HttpServerResponse
)

Source from the content-addressed store, hash-verified

311 * @since 4.0.0
312 */
313export const scopeTransferToStream = (
314 response: HttpServerResponse
315): HttpServerResponse => {
316 if (response.body._tag !== "Stream") {
317 return response
318 }
319 const fiber = Fiber.getCurrent()!
320 const scope = Context.getUnsafe(fiber.context, Scope.Scope) as Scope.Closeable
321 scopeDisableClose(scope)
322 const join: RequestScopeJoin | undefined = (scope as any)[requestScopeJoin]
323 if (join !== undefined) join.transferred = true
324 return Response.setBodyKeepHeaders(
325 response,
326 HttpBody.stream(
327 Stream.onExit(
328 response.body.stream,
329 join === undefined ? (exit) => Scope.close(scope, exit) : (exit) => join.finishBody(exit)
330 ),
331 response.body.contentType,
332 response.body.contentLength
333 )
334 )
335}
336
337const scopeEjected = Symbol.for("effect/http/HttpEffect/scopeEjected")
338

Callers 1

toWebHandlerWithFunction · 0.85

Calls 6

scopeDisableCloseFunction · 0.85
onExitMethod · 0.80
streamMethod · 0.65
closeMethod · 0.65
finishBodyMethod · 0.65
getUnsafeMethod · 0.45

Tested by

no test coverage detected