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

Function transform

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

Source from the content-addressed store, hash-verified

934 zstd: { level: levels.zstd }
935 }
936 const transform = (
937 compression: HttpPlatform["Service"]["compression"],
938 acceptEncoding: string | undefined,
939 response: HttpServerResponse
940 ): Effect.Effect<HttpServerResponse> => {
941 if (
942 response.status < 200 ||
943 response.status === 204 ||
944 response.status === 206 ||
945 response.status === 304
946 ) {
947 return Effect.succeed(response)
948 }
949 const currentEncoding = response.headers["content-encoding"]
950 if (currentEncoding !== undefined) {
951 return Effect.succeed(
952 currentEncoding.trim().toLowerCase() === "identity"
953 ? Response.removeHeader(response, "content-encoding")
954 : response
955 )
956 }
957 const body = response.body
958 if (body._tag === "Empty" || body._tag === "FormData") {
959 return Effect.succeed(response)
960 }
961 const cacheControl = response.headers["cache-control"]
962 if (cacheControl !== undefined && noTransformRegex.test(cacheControl)) {
963 return Effect.succeed(response)
964 }
965 const contentType = response.headers["content-type"] ?? body.contentType
966 if (contentType === undefined || !compressible(contentType)) {
967 return Effect.succeed(response)
968 }
969 const algorithm = compressionInternal.negotiate(acceptEncoding, preferred, compression.algorithms)
970 if (algorithm === undefined) {
971 return Effect.succeed(withVary(response))
972 }
973 const contentLength = body.contentLength ?? bodyInternal.parseContentLength(response.headers["content-length"])
974 if (contentLength !== undefined && contentLength < minSize) {
975 return Effect.succeed(withVary(response))
976 }
977 return compression.compressResponse(response, algorithm, levelOptions[algorithm])
978 }
979 return <E, R>(
980 httpApp: Effect.Effect<HttpServerResponse, E, R>
981 ): Effect.Effect<HttpServerResponse, E, R | HttpServerRequest | HttpPlatform> =>

Callers 7

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

Calls 4

compressibleFunction · 0.85
withVaryFunction · 0.85
trimMethod · 0.80
succeedMethod · 0.45

Tested by

no test coverage detected