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

Function handleResponse

packages/platform-node/src/internal/httpServer.ts:366–485  ·  view source on GitHub ↗
(request: ServerRequest.HttpServerRequest, response: ServerResponse.HttpServerResponse)

Source from the content-addressed store, hash-verified

364 )
365
366const handleResponse = (request: ServerRequest.HttpServerRequest, response: ServerResponse.HttpServerResponse) =>
367 Effect.suspend((): Effect.Effect<void, Error.ResponseError> => {
368 const nodeResponse = (request as ServerRequestImpl).resolvedResponse
369 if (nodeResponse.writableEnded) {
370 return Effect.void
371 }
372
373 let headers: Record<string, string | Array<string>> = response.headers
374 if (!Cookies.isEmpty(response.cookies)) {
375 headers = { ...headers }
376 const toSet = Cookies.toSetCookieHeaders(response.cookies)
377 if (headers["set-cookie"] !== undefined) {
378 toSet.push(headers["set-cookie"] as string)
379 }
380 headers["set-cookie"] = toSet
381 }
382
383 if (request.method === "HEAD") {
384 nodeResponse.writeHead(response.status, headers)
385 return Effect.async<void>((resume) => {
386 nodeResponse.end(() => resume(Effect.void))
387 })
388 }
389 const body = response.body
390 switch (body._tag) {
391 case "Empty": {
392 nodeResponse.writeHead(response.status, headers)
393 nodeResponse.end()
394 return Effect.void
395 }
396 case "Raw": {
397 nodeResponse.writeHead(response.status, headers)
398 if (
399 typeof body.body === "object" && body.body !== null && "pipe" in body.body &&
400 typeof body.body.pipe === "function"
401 ) {
402 return Effect.tryPromise({
403 try: (signal) => pipeline(body.body as any, nodeResponse, { signal, end: true }),
404 catch: (cause) =>
405 new Error.ResponseError({
406 request,
407 response,
408 reason: "Decode",
409 cause
410 })
411 }).pipe(
412 Effect.interruptible,
413 Effect.tapErrorCause(handleCause(nodeResponse, response))
414 )
415 }
416 return Effect.async<void>((resume) => {
417 nodeResponse.end(body.body, () => resume(Effect.void))
418 })
419 }
420 case "Uint8Array": {
421 nodeResponse.writeHead(response.status, headers)
422 return Effect.async<void>((resume) => {
423 nodeResponse.end(body.body, () => resume(Effect.void))

Callers 1

toHandledFunction · 0.85

Calls 10

handleCauseFunction · 0.85
unsafeOpenMethod · 0.80
unsafeCloseMethod · 0.80
syncMethod · 0.80
isEmptyMethod · 0.65
endMethod · 0.65
pipeMethod · 0.65
failMethod · 0.65
writeMethod · 0.65
resumeFunction · 0.50

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…