(
compression: HttpPlatform["Service"]["compression"],
acceptEncoding: string | undefined,
response: HttpServerResponse
)
| 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> => |
no test coverage detected