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

Function transform

packages/effect/src/unstable/http/HttpMiddleware.ts:488–530  ·  view source on GitHub ↗
(
    compression: HttpPlatform["Service"]["compression"],
    acceptEncoding: string | undefined,
    response: HttpServerResponse
  )

Source from the content-addressed store, hash-verified

486 zstd: { level: levels.zstd }
487 }
488 const transform = (
489 compression: HttpPlatform["Service"]["compression"],
490 acceptEncoding: string | undefined,
491 response: HttpServerResponse
492 ): Effect.Effect<HttpServerResponse> => {
493 if (
494 response.status < 200 ||
495 response.status === 204 ||
496 response.status === 206 ||
497 response.status === 304
498 ) {
499 return Effect.succeed(response)
500 }
501 const currentEncoding = response.headers["content-encoding"]
502 if (currentEncoding !== undefined) {
503 return Effect.succeed(
504 currentEncoding.trim().toLowerCase() === "identity"
505 ? Response.removeHeader(response, "content-encoding")
506 : response
507 )
508 }
509 const body = response.body
510 if (body._tag === "Empty" || body._tag === "FormData") {
511 return Effect.succeed(response)
512 }
513 const cacheControl = response.headers["cache-control"]
514 if (cacheControl !== undefined && noTransformRegex.test(cacheControl)) {
515 return Effect.succeed(response)
516 }
517 const contentType = response.headers["content-type"] ?? body.contentType
518 if (contentType === undefined || !compressible(contentType)) {
519 return Effect.succeed(response)
520 }
521 const algorithm = compressionInternal.negotiate(acceptEncoding, preferred, compression.algorithms)
522 if (algorithm === undefined) {
523 return Effect.succeed(withVary(response))
524 }
525 const contentLength = body.contentLength ?? contentLengthHeader(response.headers)
526 if (contentLength !== undefined && contentLength < minSize) {
527 return Effect.succeed(withVary(response))
528 }
529 return compression.compressResponse(response, algorithm, levelOptions[algorithm])
530 }
531 return <E, R>(
532 httpApp: Effect.Effect<HttpServerResponse, E, R>
533 ): Effect.Effect<HttpServerResponse, E, R | HttpServerRequest | HttpPlatform> =>

Callers 7

compressionFunction · 0.70
UrlParams.tsFile · 0.70
HttpClient.tsFile · 0.70
withScopeFunction · 0.70
ensureStructFunction · 0.50
getPayloadFunction · 0.50

Calls 3

withVaryFunction · 0.85
contentLengthHeaderFunction · 0.85
succeedMethod · 0.45

Tested by

no test coverage detected